Can the status
variable be used as a JSON object?
What is the method to access the values of action_success
and newIndex
within the status
object?
Server:
[HttpPost]
public ActionResult UploadFiles()
{
// save file..
return Json(new { action_success = "true", newIndex = 2 });
}
Client:
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!
}
EDIT: Simple solution:
var statusParsed = JSON.parse(status);
var success = statusParsed.action_success;
var index = statusParsed.newIndex;