I have an issue where I'm using an XHR request, but it's breaking in IE8. My hopes is to extract the XHR call, and the AJAX call, merge them and add them to the $.ajax() function like so:
var loadingXHR = {
xhr: function () {
var xhr = new window.XMLHttpRequest;
xhr.addEventListener('progress', (function (evt) {
var parentWidth, percent, percentComplete, width;
if (evt.lengthComputable) {
width = loadEl.width();
parentWidth = loadEl.offsetParent().width();
percent = 100 * width / parentWidth;
percentComplete = Math.max((evt.loaded / evt.total) * 100, percent);
loadEl.stop().animate({
width: Math.min(percentComplete, 100) + "%"
}, 120);
}
}), false);
return xhr;
}
}
var ajaxResponse = {
type: "POST",
url: url,
dataType: "json",
cache: false,
contentType: "application/json; charset=utf-8",
data: data,
error: function (xhr, textStatus, errorThrown) {
/* error */
},
success: function (model) {
/* success */
}
}
if (conditional) {
return $.ajax($.extend(loadingXHR, ajaxResponse));
}
return $.ajax(ajaxResponse);
However this option doesn't work and my only solution is to create two different AJAX calls and wrap that in a conditional.