开发者

ignore ajax setup

开发者 https://www.devze.com 2023-01-14 07:34 出处:网络
is there any way of ignoring the optio开发者_StackOverflow中文版ns set with $.ajaxSetup for a specific request?This is kludgey but should work:

is there any way of ignoring the optio开发者_StackOverflow中文版ns set with $.ajaxSetup for a specific request?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消