views:

23

answers:

2

is there any way of ignoring the options set with $.ajaxSetup for a specific request?

A: 

There isn't any built-in functionality to do this. The very first thing any $.ajax() call does is merge options with $.ajaxSettings, there's no bypass for this.

Any of the $.ajax() shorthand methods (.load(), $.post(), etc) are still calling $.ajax() underneath, so they're in the same boat.

Nick Craver
A: 

This is kludgey but should work:

var origAjaxSettings = {};

function ajaxSettingsDisable() {
    jQuery.extend(origAjaxSettings, jQuery.ajaxSettings);
    jQuery.ajaxSettings = {};
}

function ajaxSettingsEnable() {
    jQuery.extend(jQuery.ajaxSettings, origAjaxSettings);
    origAjaxSettings = {};
}

//ajax request of any sort
ajaxSettingsDisable();
$.ajax({
    //Ajax request settings
});
ajaxSettingsEnable();

This could be extended to make it a jQuery plug-in.

Gutzofter
jQuery ajax settings don't have all options by default, for example if you added a `success` handler it would still apply :)
Nick Craver