javascript - in jquery how to call a function after an ajax request has been sent? -
how can call function: myfunc1 in jquery after browser has sent ajax request?
i want run callback function after jquery ajax has been sent. don't want on complete or success because don't want wait request complete. want fire right after ajax request has been sent browser.
this use case need this:
i want run function after making ajax request. original code this:
$.ajax({url: 'x.html'}); myfunc1(); in case when `myfunc1() changes browsers location, browser cancel pending ajax request.
my current solution this:
$.ajax({url: 'x.html', complete: myfunc1}); this makes sure myfunc1 not called till ajax complete. although solution works, inefficient because myfunc1 wont run till request complete. since don't care ajax request returns, whether fails or succeeds, dont need wait complete run myfunc1 function.
if @ specification:
http://www.w3.org/tr/xmlhttprequest/
you'll see 2 means headers have been returned already.
const unsigned short **headers_received** = 2; this same jqxhr success. browser may vary =)
no seriously.. vary, reason jquery can't support them , chooses abstract them:
http://msdn.microsoft.com/library/ie/ms534361.aspx
https://developer.mozilla.org/en-us/docs/web/api/document.readystate
(couldn't find authoritative source chrome)
Comments
Post a Comment