你好我想知道这是否可行?
$results = $stmt->fetchAll();
$recent_posts = array();
foreach ($results as $row){
$post = array(
'username' => $row['username'],
'steam' => $row['steam'],
'skill' => $row['skill'],
'description' => $row['description'],
'date' => $row['date'],
);
array_push($recent_posts, $post);
}
return json_encode($recent_posts);
如果可以的话,我究竟如何在jquery中访问它? $
('#order_by').on('change', function(){
$.ajax({
type: "POST",
url: "sort_skill_be.php",
data: { skill: this.value },
error: function (qXHR, textStatus, errorThrown) {
console.log(errorThrown);
//alert(errorThrown);
},
success: function (result) {
alert(result[0].skill); // CAN I ACCESS IT LIKE THIS?
}
});
});
这是我到目前为止所做的,但我一直都会遇到奇怪的错误。当我添加datatype:json
时,我一直遇到问题。所以我觉得我处理的不正确,谢谢你的帮助!