status
是否是可用的JSON对象?
如何在action_success
上访问newIndex
和status
的值?
服务器:
[HttpPost]
public ActionResult UploadFiles()
{
// save file..
return Json(new { action_success = "true", newIndex = 2 });
}
客户端:
complete: function (e, data) {
var status = e.currentTarget.response;
// From FireBug: status is "{"action_success":"true","newIndex":2}"
// Including the first and last double-quote.
// I want to do something like:
// status.action_success and status.newIndex but I can't!
}
修改 简单的解决方案:
var statusParsed = JSON.parse(status);
var success = statusParsed.action_success;
var index = statusParsed.newIndex;
答案 0 :(得分:0)
我认为您可以直接使用JsonResult并且应该可以使用
[HttpPost]
public JsonResult UploadFiles()
{
// save file..
return Json(new { action_success = "true", newIndex = 2 });
}
在客户端如果使用$ .ajax(),则将数据类型设置为json