Let’s say I’m $.post()-ing an AJAX request to a script that does the following:
echo "foo";
sleep(60); // block request for some time
echo "bar";
Will the originating script fire the success function when it sees “foo”, or when the ajax script is finally done after “bar” is echoed?
There may be several
readystatechangeevents while the response arrives, but thereadyStateonly changes to 4 (Loaded) when the response is complete.The jQuery library will call the
successmethod when areadystatechangeevent happens and thereadyStateproperty is 4 (Loaded), andstatusproperty shows a successful status code (e.g. 200).