如何从 JSON 值获取显示返回值。我需要获取用户 ID 的值
$('User_id').observe('blur', function(e) {
var txt = $('User_id').value;
jQuery.ajax({
type: 'get',
url: BASE_URL + 'admin/index/user_id',
data: {
user_id: txt
},
dataType: 'json',
success: function(data) {
console.log('success' + data.success);
if (data.success) {
var Value = data.location.user_id;
alert(Value);
}
}
});
});
这些值以 html 形式获取。因为我需要将用户 ID 存储在值变量中。但我收到 successundefined 作为输出..
[{
"user_id": "139",
"mobile": "9042843911",
"gender": "male",
"hashcode": "DfAbMqLApAV6nVa1z940",
"username": "anandhsp21",
"password": "74bcff7d1199012e154f364e3f65e31d:8I",
"authorized_person": "Anandh",
"created": "2015-06-08 13:46:55",
"modified": "2015-06-08 06:43:35",
"logdate": "2015-06-08 08:16:55",
"lognum": "12",
"reload_acl_flag": "0",
"is_active": "1",
"extra": "N;",
"rp_token": null,
"rp_token_created_at": null,
"app_name": "",
"api_key": ""
}]
请有人帮忙。提前致谢
最佳答案
您获取数组中的数据,因此在成功数据中使用循环
for (var i=0; i<data.length; i++) {
console.log('success' + data[i].user_id );
}
如果知道记录长度为1则直接使用
console.log('success' + data[0].user_id );
关于javascript - 如何显示从 jQuery 返回的 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30707319/