Reputation: 12173
In jQuery is there a callback that can be used when an ajax request is finished loading. The reason I am wondering is because I'd like to display a loading gif until the the ajax request is finished.
Upvotes: 0
Views: 120
Reputation: 18531
Yes there is http://api.jquery.com/jQuery.ajax/
success(data, textStatus, jqXHR) A function to be called if the request succeeds.
or
error(jqXHR, textStatus, errorThrown) A function to be called if the request fails.
or even:
complete(jqXHR, textStatus) A function to be called when the request finishes (after success and error callbacks are executed).
Upvotes: 0
Reputation: 1211
Yes, if you look at the jQuery documentation, there is a callback value you can set.
complete(jqXHR, textStatus) or maybe success(data, textStatus, jqXHR)?
http://api.jquery.com/jQuery.ajax/
Just set a property named "success" or "complete" with a function you want called on your ajax setting object that you pass in on your ajax call and it should get invoked when the request is complete.
Upvotes: 0
Reputation: 6432
See this page regarding ajax events. All you will need to do is bind to ajaxComplete
and then you can clear you loading picture from there.
Upvotes: 2