600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > php怎么遍历json字符串数组 php-使用jquery遍历json数组

php怎么遍历json字符串数组 php-使用jquery遍历json数组

时间:2020-03-02 11:40:52

相关推荐

php怎么遍历json字符串数组 php-使用jquery遍历json数组

我从jQuery中获取错误:

a为空

这是因为我添加了循环遍历json数据的代码:

$(function ()

{

$.ajax({

url: 'ajax_dashboard/api.php', //the script to call to get data

data: "",

dataType: 'json',

success: function(data)

{

$.each(data, function() {

$.each(this, function(k, v) {

$('#output').append("key:"+k+"value:"+v)

.append("

");

});

});

}

});

});

这是php文件(我确实验证了给出的有效JSON格式):

$query_camera_name = "SELECT camera_name, camera_status, camera_quality, email_notice, camera_hash, camera_type FROM #__cameras WHERE user_id=".$user->id." AND camera_status!='DELETED'";

$db->setQuery($query_camera_name);

//get number of cameras so we can build the table accordingly

$db->query();

$num_rows = $db->getNumRows();

// We can use array names with loadAssocList.

$result_cameras = $db->loadAssocList();

echo json_encode($result_cameras);

?>

这将返回以下json格式的数据:

[

{

"camera_name": "ffgg",

"camera_status": "DISABLED",

"camera_quality": "MEDIUM",

"email_notice": "DISABLED",

"camera_hash": "0d5a57cb75608202e64b834efd6a4667a71f6dee",

"camera_type": "WEBCAM"

},

{

"camera_name": "test",

"camera_status": "ENABLED",

"camera_quality": "HIGH",

"email_notice": "ENABLED",

"camera_hash": "6ab000ef7926b4a182f0f864a0d443fc19a29fdd",

"camera_type": "WEBCAM"

}

]

如果删除循环,“ a为null”错误将消失.我究竟做错了什么?

解决方法:

该错误在其他地方.

编辑:

试试这个来帮助调试.

success: function(data, textStatus, xhr) {

console.log(xhr);

...

}

xhr将包含许多有关发出请求的信息. responseText包含什么?什么是statusText?

标签:json,php,jquery

来源: https://codeday.me/bug/1202/2085323.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。