Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery: how to check if a page is performing an ajax request?

Tags:

jquery

ajax

I want to build a function that fires with every ajax request. Like showing "loading...". I am using Jquery is that possible?

like image 390
safiot Avatar asked Dec 05 '22 16:12

safiot


2 Answers

jQuery.active contains the number of active jQuery AJAX connections. However, you'd have to constantly poll that var in order to have an event fired in the advent of a new connection.

Anyway, why would you be using this for a "loading" indicator? Just set the indicator whenever you do the request.

like image 66
ubik Avatar answered Mar 05 '23 02:03

ubik


Yes, this is totally possible. Start with the global ajax handlers here http://api.jquery.com/category/ajax/global-ajax-event-handlers/ .ajaxStart() and .ajaxStop() events are the most likely candidate to show your status indicator.

like image 40
Chad Ruppert Avatar answered Mar 05 '23 02:03

Chad Ruppert