Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent overwriting jQuery's $.ajaxSetup() options?

Tags:

jquery

ajax

I've got a question concerning ajaxSetup. When the script starts, I define the following:

$.ajaxSetup({
  success: function(data) {
    example(); 
  }
});

Up to here everything works fine. The problem starts by using Ajaxify, which overwrites the success function.

How can I prevent this? Is there a possibilty to execute both functions or to add the setup success function to that one which I call in the main AJAX request?

like image 660
Tobias Bambullis Avatar asked Feb 25 '23 09:02

Tobias Bambullis


1 Answers

Use callback function defined in ajaxsetup.
Define

$.ajaxSetup({
    beforeSend      : function() {
        $('#ajaxLoader').show();
        ...
    }
});

and call later

$.ajax({
    beforeSend: function() {
        $.ajaxSettings.beforeSend();
        // do other
        ...
    }
});    
like image 136
sandex Avatar answered Mar 07 '23 12:03

sandex