I have the following ajax call in my javascript. This call executes correctly, the appropriate action is taken on the server, and the server returns status 200 and a JSON object containing: a string name result containing the value "OK" and an array of tuples called aaData. I can see this returned data by spying out the results in Chrome.
My problem is that while alert("Hello") executes as expected, and alert(response) displays “object” (as I would expect); alert(response["result"] displays “undefined”. It appears to me that response has already been parsed into a javascript object and I should be able to use it. Am I wrong? Is there something else I need to do to the object? Or am I addressing its elements incorrectly.
$.ajax( {type: "PUT",
url: "/fund/${fund.name}/contacts",
data: payload,
contentType: "application/json",
processData: false,
cache: false,
dataType: "application/json",
complete: function(response) {
alert("Hello");
alert(response);
alert(response["result"]);
if (response["result"] != "OK")
{
alert(response["result"])
}
else
{
$("#fund-contacts").dataTable( {"aaData": response["aaData"]} )
}
$("#fund-contact-entry").dialog( "close" );
alert("Hello");
}
}
);
Use the
successcallback instead ofcomplete.From the manual
Edit: Also, what @hobbs says above