[英]get ajax $.post array response
I am having trouble what to do with the array response of the ajax $.post request: 我在处理ajax $ .post请求的数组响应时遇到了麻烦:
$.post(
'../php/adminindex.php',
{'functions': 'userdetail', 'userId': $('#selViewUserId').val()},
function(data) {
//var response = jQuery.parseJSON(data);
//alert(typeof(data));
alert(data);
}
);
the alert(data)
returns: alert(data)
返回:
<pre class='xdebug-var-dump' dir='ltr'>
<b>array</b> <i>(size=1)</i>
0 <font color='#888a85'>=></font>
<b>array</b> <i>(size=4)</i>
'user_id' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'ADMIN'</font> <i>(length=5)</i>
'user_last' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'Admin'</font> <i>(length=5)</i>
'user_first' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'Test'</font> <i>(length=4)</i>
'user_type' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'5'</font> <i>(length=1)</i>
The commented 2 lines does not have any response and I can't figure out what is the problem. 评论2行没有任何回应,我不能弄清楚是什么问题。
I wanted to get the values inside data but data[0]['user_id']
and data[0]
does not return the desired output. 我想获取数据内部的值,但data[0]['user_id']
和data[0]
无法返回所需的输出。
How can I get those data out for use? 如何获取这些数据以供使用?
from your comment, it looks like you are receiving an array. 从您的评论看来,您似乎正在接收一个数组。 Try accessing user id with 尝试使用访问用户ID
data[0].user_id
关于您的评论 ,您可以通过以下操作访问您的数据:
var user_id = data[0].user_id;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.