解析jQuery AJAX响应 [英] Parsing jQuery AJAX response
本文介绍了解析jQuery AJAX响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下函数通过jQuery AJAX发布表单:
I use the following function to post a form to via jQuery AJAX:
$('form#add_systemgoal .error').remove();
var formdata = $('form#add_systemgoal').serialize();
$.ajaxSetup({async: false});
$.ajax({
type: "POST",
url: '/admin/systemgoalssystemgoalupdate?format=html',
data: formdata,
success: function (data) {
console.log(data);
},
});
它发布得很好,但是我无法解析响应,它记录到控制台如下
It posts fine but I cannot parse the respons, it logs to console as follows
{
"success": 1,
"inserted": {
"goal_id": "67",
"goalsoptions_id": "0",
"user_id": "0",
"value": "dsfdsaf",
"created": "2013-06-05 09:57:38",
"modified": null,
"due": "2013-06-17 00:00:00",
"status": "active",
"actions_total": "0",
"actions_title": "sfdgsfdgdf",
"action_type": "input",
"points_per_action": "1",
"expires": "2013-06-11 00:00:00",
"success": 1
}
}
我相信这是我正在寻找的答案.
which I believe is the response I am looking for.
但是,当我尝试执行alert(data.success);
或响应对象的其他任何成员时,它都是undefined
.
However when I try to do alert(data.success);
or any of the other members of the response object it is undefined
.
任何建议表示赞赏.
推荐答案
调用
var parsed_data = JSON.parse(data);
应该可以随心所欲地访问数据.
should result in the ability to access the data like you want.
console.log(parsed_data.success);
现在应显示"1"
这篇关于解析jQuery AJAX响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文