JSFiddle - React, Tailwind, and code Playground
HTML
<pre id="log"></pre>
JavaScript
jQuery.ajaxPrefilter(function( options, _, jqXHR ) {
if ( jQuery.isFunction( options.progress ) ) {
var xhrFactory = options.xhr,
interval;
options.xhr = function() {
var xhr = xhrFactory.apply( this, arguments ),
partial = "",
prevcount = 1;
interval = setInterval(function() {
var responseText,
jQueryPartial;
try {
responseText = xhr.responseText;
if ( responseText && ( responseText.length > partial.length ) ) {
partial = responseText;
jQueryPartial = $( partial ).filter("*")
if ( jQueryPartial.length > prevcount ) {
prevcount = jQueryPartial.length;
options.progress( jQueryPartial.filter("*:not(:last)") );
}
}
} catch(e) {
log(e);
}
}, options.progressInterval );
return xhr;
};
function stop() {
if ( interval ) {
clearInterval( interval );
}
}
jqXHR.then( stop, stop );
}
});
jQuery.ajaxSetup({
progressInterval: 1
});
function log(s) {
$("#log").append(s + "<br>");
}
function loaddata(data, isfinal) {
log("loaddata called with " + (isfinal ? "final" : "partial") + " content");
}
var xhr = $.ajax({
type: "GET",
url: '/',
progress: loaddata,
success: function(data) {
log("ajax success");
loaddata(data, true);
},
error: function( _, _, e ) {
log("ajax error");
console.log( e );
}
});