progress bar for multiple ajax jsonp processes
My web app requests information from several different web servers via jsonp ajax requests. Some complete immediately while others take longer. I would like to show a little 开发者_如何学运维whirly animation in a div until all requests complete. Of course, jQuery's $.ajaxStart()
and $.ajaxComplete()
don't work with jsonp. What can I do?
update: turns out, the "beforeSend" and "complete" options of the $.ajax
work just fine. Problem solved.
In my JavaScript, I added the beforeSend
and complete
options:
$.ajax({
"url": "path/to/web/server",
"data": data,
"type": "GET",
"dataType": "jsonp",
"beforeSend": function() {
$('#loading').show();
},
"complete": function() {
$('#loading').hide();
},
"success": function(data) {
..
}
});
and, in my html, a div with the loading image
<div id="loading" style="display: none;">
<img src="img/loading.gif" />
</div>
The above works well.
精彩评论