Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

jquery - Can I retrieve (event, xhr, options) from .ajaxStart or .ajaxStop?

Based on http://api.jquery.com/ajaxComplete/

.ajaxComplete( handler(event, XMLHttpRequest, ajaxOptions) )
.ajaxStart( handler(event) )

To my knowledge and experiements, the XMLHttpRequest and ajaxOptions parameters for the handler of .ajaxStart or .ajaxStop are null.

I would like to retrieve the ajaxOptions information inside the functions of .ajaxStart and .ajaxStop. Is that possible?

What problems will I have if I hook up with .ajaxSend + .ajaxComplete rather than .ajaxStart + .ajaxComplete. The major reason I like to do so is that .ajaxSend can access all three parameters.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can't access them here because these events are for when the active count of requests changes to above 0 and back, but aren't per-request, they're for overall activity.

I think what you're after is .ajaxSend() and .ajaxComplete() which fire per-request and have the requested parameters, for example:

$(document).ajaxSend(function(event, xhr, options) {
  //do start stuff
}).ajaxComplete(function(event, xhr, options) {
  //do end stuff
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...