从MySQL获得在jQuery的AJAX成功Specfic响应 [英] Get Specfic response from MySql in jQuery AJAX Success
本文介绍了从MySQL获得在jQuery的AJAX成功Specfic响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗯,我有这样的阿贾克斯code这会从MySQL的成功块返回结果。
Well i have this ajax code which will return the result from MySql in Success block.
$.ajax({
type:"POST",
url:"index.php",
success: function(data){
alert(data);
}
});
我的查询
$sql = "SELECT * FROM tablename";
$rs=parent::_executeQuery($sql);
$rs=parent::getAll($rs);
print_r($rs);
return $rs
在成功AJAX的提醒我的反应阵列
My Response Array in alert of Success AJAX
Array
(
[0] => Array
(
[section_id] => 5
[version] => 1
[section_name] => Crop Details
[id] => 5
[document_name] => Site Survey
[document_master_id] => 1
[document_section_id] => 5
)
[1] => Array
(
[section_id] => 28
[version] => 1
[section_name] => Vegetative Report
[id] => 6
[document_name] => Site Survey
[document_master_id] => 1
[document_section_id] => 28
)
)
我想只得到 SECTION_NAME 和 DOCUMENT_NAME 的结果,这样我可以追加这两个值进入我的列表。
I want to get only section_name and document_name from the result so that i can append these two values to my list.
推荐答案
如果使用不返回响应的print_r()
,使用 json_en code()
:
Don't return the response using print_r()
, use json_encode()
:
echo json_encode($rs);
然后在Javascript中,你可以这样做:
Then in the Javascript, you can do:
$.ajax({
type:"POST",
url:"index.php",
dataType: 'json'
success: function(data){
for (var i = 0; i < data.length; i++) {
console.log(data[i].section_name, data[i].document_name);
}
}
});
这篇关于从MySQL获得在jQuery的AJAX成功Specfic响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文