我有一个多维数组,我不知道如何在ajax响应中检索其值。请帮助我解决这个问题。预先感谢。
这是我从ajax响应中的console.log获取的数组
0:{id:“ 3”,chat_id:“ 1”,to_user_id:“ 2”,to_user_name:“ peter_Parker”,from_user_id:“ 1”,...}
1:{id:“ 4”,chat_id:“ 3”,to_user_id:“ 3”,to_user_name:“ david_Moore”,from_user_id:“ 1”,...}
我尝试了一些代码,但是没有用
function open_chatbox(){
$.ajax({
url:"open_chatbox.php",
method:"POST",
dataType:'json',
success:function(data)
{
console.log(data);
for (var i = 0; i < data.length; i = i+1)
{
var status = data['i'].status;
var to_user_id = data['i'].to_user_id;
var to_user_name = data['i'].to_user_name;
var from_user_id = data['i'].from_user_id;
var from_user_name = data['i'].from_user_name;
var chat_id = data['i'].chat_id;
if('<?php echo $_SESSION['user_id']?>'== from_user_id && status==1)
{
if($('#user_dialog'+to_user_id).length == 0)
{
make_chat_box(to_user_id, to_user_name,chat_id);}
}
}
}
})
}