我使用以下函数通过 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);
},
});
它发布得很好,但我无法解析响应,它记录到控制台如下
{
"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
}
}
我相信这是我正在寻找的回应。
但是,当我尝试做alert(data.success);
或响应对象的任何其他成员时,它是undefined
.
任何建议表示赞赏。