这是我的Ajax POST
请求:
function getRelated() {
var elements = (document.getElementsByClassName('escashare'));
var query = [];
for(var i=0;typeof(elements[i])!='undefined';query.push(elements[i++].getAttribute('data-id')));
$.ajax({
type: "POST",
url: baseUrl+"/requests/get_related.php",
data: "query="+query+'&_token='+_token,
cache: false,
success: function(html){
$('#main-content').append(html);
}
});
}
所以基本上我POST
是一个数字数组,int
例如:
["326", "311", "312", "313", "314", "316", "317", "318", "319", "15", "9", "87"]
当在我的 PHP中时implode
,query
它给了我数组,NULL
但为什么呢?
$newQuery = implode(',', $QueryFromPost);
var_dump($newQuery); //NULL
编辑
我需要将它用于:
$query = $this->db->query(sprintf("SELECT * FROM `posts` WHERE `id` IN ('%s')", $newQuery));
while($result = $query->fetch_assoc()) {
$rows[] = $result;
}
if(!empty($rows)) {
foreach($rows as $row) {
$output .= '<div class="stage">'.$row['id'].'</div>';
}
}
return $output;