In the stub code below, when the error: method is invoked, the "errorThrown" variable just returns "object Object".
How can I get it to print out the actual text?
jQuery.ajax
({
contentT开发者_JAVA技巧ype: "application/json; charset=utf-8",
dataType: "json",
url: myURL,
success: function(data)
{
if(data['response'] === undefined){
this.error('No data returned');
}
//success code goes here
},
error: function(errorThrown)
{
result += errorThrown;
alert('The error was: '+errorThrown);
return;
}
});
The error function receives three arguments. The first is a jQueryXmlHttpRequest Object, the second and third are probably useful to you:
error: function(jqXHR, textStatus, errorThrown){
alert('Error Message: '+textStatus);
alert('HTTP Error: '+errorThrown);
}
The first parameter passed to the jQuery ajax error function is of type jqXHR (XMLHttpRequest in jQuery 1.4.x. http://api.jquery.com/jQuery.ajax/#jqXHR
The response will be contained in the responseText property:
error: function(errorThrown)
{
result += errorThrown.responseText;
alert('The error was: '+errorThrown.responseText);
return;
}
精彩评论