??yy 2015-01-19 01:30 采纳率: 0%
浏览 23

获取ajax $ .post数组响应

I am having trouble what to do with the array response of the ajax $.post request:

$.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:

<pre class='xdebug-var-dump' dir='ltr'>
<b>array</b> <i>(size=1)</i>
0 <font color='#888a85'>=&gt;</font> 
<b>array</b> <i>(size=4)</i>
  'user_id' <font color='#888a85'>=&gt;</font> <small>string</small> <font    color='#cc0000'>'ADMIN'</font> <i>(length=5)</i>
  'user_last' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'Admin'</font> <i>(length=5)</i>
  'user_first' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'Test'</font> <i>(length=4)</i>
  'user_type' <font color='#888a85'>=&gt;</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.

I wanted to get the values inside data but data[0]['user_id'] and data[0] does not return the desired output.

How can I get those data out for use?

  • 写回答

2条回答 默认 最新

  • weixin_33739646 2015-01-19 01:44
    关注

    In relation to your comment, you can access your data by doing the following:

    var user_id = data[0].user_id;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败