我有一个验证用户名/密码的函数:
这是JSON RESPONSE:
{"data":{"user_id":"2","auth_token":"x"},"result": {"errorcode":"","messages":"Success:Logged On","rstatus":1}}
我希望能够解析出user_id,auth_token,errorcode,message,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
}
});
}
任何建议都将不胜感激。
答案 0 :(得分:1)
怎么样:
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;
答案 1 :(得分:1)
尝试如下,
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;