Development feature: disable jQuery ajax
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(){};
精彩评论