This is really boggling my mind. I get an error callback from ajax. But if I take the res.responseText (which comes back correct, btw) from the error message and use it, it does the right thing. Just as if I had received a success callback.
The data is set like this:
var dataToSend = {fieldname : textdata};
and the ajax call is like this:
var ajaxOptions = {
url: '/newpage',
data: JSON.stringify(dataToSend),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
cache: false,
processData: false,
type: 'POST',
success: function(res) {
console.log("success!");
$('#' + divname).html(res);
},
error: function(res) {
console.log("There was an error: " + JSON.stringify(res));
$('#' + divname).html(res.responseText);
}
};
$.ajax(ajaxOptions);
The error message is : There was an error: {"readyState":4,"responseText" [this part is perfectly fine], "status":200, "statusText":"OK"}
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…