【发布时间】:2014-07-16 02:31:27
【问题描述】:
status 是可用的 JSON 对象吗?
如何访问status 上的action_success 和newIndex 的值?
服务器:
[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;
【问题讨论】:
-
嗯我需要 JSON.parse()?
-
我在写这个问题时并不知道 JSON.parse()。我是我后来找到的东西。我现在正在尝试,不要恨我。
-
JavaScript中使用了哪些AJAX API,它是如何发起的? (jQuery 通常会默认自动解析 JSON。)
-
我可以通过 "." 访问 action_success 和 newIndex现在从状态开始,在添加此行之后:` var statusParsed = JSON.parse(status); `
-
@user2864740 我不明白你的意思。我可以告诉你我的 jQuery 版本和 wijmo 的版本,如果是这样的话?这是您在我的客户端看到的 wijUpload 函数。
标签: javascript ajax json response