Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if HTTP method (POST, GET) in jQuery.ajaxComplete()

Tags:

jquery

ajax

http

In a jQuery.ajaxComplete() how can I detect the HTTP method, specifically a GET or a POST?

I've tried reading the jQuery documentation and searching around and I can't seem to find much documentation of the 3 objects passed to the function handler inside

jQuery(element).ajaxComplete(function(event, request, settings) {    });

Thanks

like image 724
Kirby Avatar asked Jul 15 '11 16:07

Kirby


Video Answer


1 Answers

The settings object in the AJAX callback is the settings object that was passed into the AJAX call. You can therefore look for the type property on it to see whether it was GET or POST:

jQuery(element).ajaxComplete(function(event, request, settings) {
    alert(settings.type);
});

The settings that you can retrieve in this manner are the same as those that you can set with the $.ajax constructor.

like image 66
lonesomeday Avatar answered Sep 27 '22 21:09

lonesomeday