I’m having a problem where the data object passed to my complete() callback function is not a json object, but rather is an [Object object]. I can see a string of my json response in data.responseText.
Here is my jQuery .ajax request:
$.ajax({
url: 'api.php',
dataType: 'json',
data: {
command: "GetBlacklist"
},
type: 'POST',
error: function(jqXHR, textStatus, errorThrown)
{
messageDiv.append("Error: " + errorThrown + "<br />");
},
complete: function(json)
{
$('.blacklist textarea').text(json.message);
messageDiv.append("Blacklist loaded.");
}
});
And here is the response that is being sent:
{"message":"success","result":0}
It evaluates to valid JSON, and I am sending the correct json content-type headers from the server. Stumped on this one!
The
completecallback’s signature iscomplete(jqXHR, textStatus),jqXHRgives you [Object object].Instead, you should use
success(data, textStatus, jqXHR)callback, which will be called if the request succeeds, and this time thedatawill give you the right thing.More info please check the manual.