I have really strange problem with ajax json response. The data in the json response (jqXHR.responseJSON
) does not match the string response data (jqXHR.responseText
). Request is without any errors (returning status code 200 OK) with json string data:
{"pdata":{"1":{"x":158,"y":545},"2":{"x":259,"y":179},"3":{"x":503,"y":77},"4":{"x":435,"y":528}},"status":"0","result":true}
I have simle code for console logging:
var loadItemData = function(image) {
var data = {};
// Prepare request data
data.image = image;
data.token = $this.getOpt('token');
// Call image get data url
$.ajax({
url: $this.getOpt('image_get_data_url'),
type: 'post',
data: data,
dataType: 'json',
success: function(json, textStatus, jqXHR) {
console.log(jqXHR.responseText);
console.log(jqXHR.responseJSON);
console.log($.parseJSON(jqXHR.responseText));
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
};
The console output from ajax success callback above is:
The question is, why responseJSON has different data as responseText and why manually parsed responseText giving right data output?
I noticed this problem after deploying changes on test server and don't have this problem on localhost (WAMP server). Using Firefox 66.0.5 (32-bit). Its developer tool showing correct data in Network tab for this request.