Ajax call returns an array of objects -
This is an example of result output.
{"FileName":"example.jpg","Statuses":null,"ProductMatchedByCode":{"ProductID":"00000000-0000-0000-0000-000000000000","ProductDetailID":"00000000-0000-0000-0000-0","Code":"","Title":"","ProductImages":[{"Path:"\\v4\\images\example.jpg","Date":null,"OriginalFileName":"example.jpg","FileSize":null}],"IsSuccesfull":false,"StatusCode":200,"StatusMessage":""},"IsSuccessful":true,"StatusCode":200,"StatusMessage":'example.jpg' Uploaded Successful"}
{"FileName":"example2.jpg","Statuses":null,"ProductMatchedByCode":{"ProductID":"00000000-0000-0000-0000-000000000000","ProductDetailID":"00000000-0000-0000-0000-0","Code":"","Title":"","ProductImages":[{"Path:"\\v4\\images\example2.jpg","Date":null,"OriginalFileName":"example2.jpg","FileSize":null}],"IsSuccesfull":false,"StatusCode":200,"StatusMessage":""},"IsSuccessful":true,"StatusCode":200,"StatusMessage":'example2.jpg' Uploaded Successful"}
But Status Message was undefined, also I think I used the wrong way for result.length it doesn't give real objects length, it gives me something bigger ex.525.Any idea how can I fix it?
What I have tried:
$.ajax({
url: self.webserviceUploadImageUrl,
type: 'POST',
processData: false,
contentType: false,
cache: false,
data: formData,
success: function (result) {
for (var i = 0; i < result.length;i++) {
var statusmsg = JSON.stringify(result[0]).StatusMessage;
}
var url = location.protocol + '//' + location.host + location.pathname;
if (url.indexOf('?') > -1) {
url += '&message=' + statusmsg;
} else {
url += '?message=' + statusmsg;
}
window.location.href = url;
},
error: function () {
self.statusMessage("Error uploading product images. Please refresh the page and try again");
}
});