Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery嵌套响应数组问题_Jquery_Ajax_Json - Fatal编程技术网

jQuery嵌套响应数组问题

jQuery嵌套响应数组问题,jquery,ajax,json,Jquery,Ajax,Json,我有一个验证用户名/密码的函数: 以下是JSON响应: {数据:{user_id:2,auth_token:x},结果:{errorcode:,消息:成功:登录,rstatus:1} 我希望能够解析出用户id、身份验证令牌、错误代码、消息、rstatus 以下是调用的JQuery代码: function authenticate(userName, password) { $.ajax({ url: 'index.php?action=login', ty

我有一个验证用户名/密码的函数:

以下是JSON响应:

{数据:{user_id:2,auth_token:x},结果:{errorcode:,消息:成功:登录,rstatus:1}

我希望能够解析出用户id、身份验证令牌、错误代码、消息、rstatus

以下是调用的JQuery代码:

function authenticate(userName, password) {
    $.ajax({
        url: 'index.php?action=login',
        type: 'POST',
        contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
        data: 'username=' + userName + '&password=' + password,
        dataType: 'json',
        async: true,
        success: function (response) {
            //i need to parse out the data here
        }
    });
}
如有任何建议,我们将不胜感激。

如何:

var user_id = response.data.user_id, 
    auth_token = response.data.auth_token, 
    errorcode = response.result.errorcode, 
    messages = response.result.messages, 
    rstatus = response.result.rstatus;
试着像下面这样

var user_id = response.data.user_id,
   auth_token = response.data.auth_token,
   errorcode = response.result.errorcode,
   messages = response.result.messages,
   rstatus = response.result.rstatus;

错误代码、消息和rstatus来自response.result.:P@Vega-Bah,应该检查一下,查看JSON以快速:p这可能会在将来帮助您。请仔细阅读。。谢谢格雷库斯。。。成功了!