How can I set different settings (jQuery.ajaxSetup()) for different AJAX requests?
What I would like to do is to "link" each AJAX call do different ajaxSetup().
The point of $.ajaxSetup() is to create default settings for all ajax calls via jQuery on a global scale. If you want to override settings, just specify them in the specific ajax call.
For instance, somewhere early in your code, define your $.ajaxSetup():
$.ajaxSetup({
type: 'POST'
, cache: false
, contentType: 'application/json'
, dataType: 'json'
, error: function (a, b, c) {
//default error handling
console.log(a, b, c);
}
});
Then when you want to override, say, using a GET, do something like:
$.ajax(myUrl, {
type: 'GET'
, data: myData
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With