beginner beginner - 1 year ago 67
Javascript Question

When the ajax call is fully completed?

when any ajax call is done by clients , Clients uploads data to server(HTTP request) and then receive data from server(HTTP Response), when the data is received totally by clients, the ajax request is consider successful and success callback function is executed ,

But when i try to track ,this data transfer between client and server , by using


xhr: function(){

var xhr = $.ajaxSettings.xhr() ;

xhr.upload.onprogress = function(e){console.log('upload progress',e.loaded/*100) } ;
xhr.onprogress = function(e){console.log('total downloaded',e.loaded)}
return xhr ;

In this ajax request , server is sending 277695 bytes file , But
The data is not completely downloaded, still it says XHR finished loading , Why after some part is downloaded first , And XHR request is become complerted ,

enter image description here

We can see here server a is sending a file of length 277695 bytes , But only the 7946 bytes downloaded , and it says xhr finished loading , I was expecting , all file (277695 bytes)should be downloaded before XHR finsihed loading. So can someone explain why only some part of file is downloaded first ?


And i also want to ask when the success call back function is executed, because it will be executed when whole result(response) received from server . So when the success callback function will be executed ? after total download is 7946, OR after the whole data downloaded , i.e total downloaded is 277695

Answer Source

The log XHR finished loading... is made by the network monitoring that is part of your console. The point is that this log is made almost at the same time that the true complete transfer has happened, not immediately(!) after the 7946 bytes were read. In short, it is OK like it is. Just use the load event, which triggers immediately(!) after you get the XHR finished message.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download