开发者

Development feature: disable jQuery ajax

开发者 https://www.devze.com 2023-03-30 11:26 出处:网络
is it possible to disable jQuery ajax() ca开发者_Python百科lls? As a developer, I ofttimes need to test site without ajax (without actually turning js off).

is it possible to disable jQuery ajax() ca开发者_Python百科lls? As a developer, I ofttimes need to test site without ajax (without actually turning js off).

I would create a script that utilizes local database: when certain link is clicked, it would toggle a property. Ie. how can I effect global bindings such as

$("a.ajax").live("click", function (event) {
    event.preventDefault();
    $.get(this.href);
});

without actually changing the code itself? Could I replace the ajax() function? How would you deal with this?


You can override jQuery's get method with an empty annonymous function of your own, before any of your code is run:

$.get = function(){};

Or you could use jQuery's $.noop, which is basically the same thing:

$.get = $.noop;


Using global handlers, you can do something like this..

$(document).ajaxStart(function() {
  return false;
});


Override $.ajax to an empty function which do not do anything.

$.ajax = function(){};
0

精彩评论

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