views:

2130

answers:

7

The subject says it all: Is it possible to disable AJAX without disabling JavaScript completely?

Thank you all!

Regards, Frank

A: 

No. AJAX is just a particular use of javascript.

If you could block the particular function call back to the server you might be able to do it, but you would probably have to edit your browser.

I assume you want to do this from the client end... Can you list some more specific goals? What is the expected outcome?

Sam Hoice
+4  A: 

AJAX is simply the usage of the XMLHttpRequest function in Javascript. Depending on your browser, you may be able to lock down access to this function through your security settings. At least with Firefox, you could disable it either through using a custom Extension.

Lokkju
+12  A: 

If you are using Firefox, you could accomplish this with GreaseMonkey. (https://addons.mozilla.org/en-US/firefox/addon/748)

GM is a framework for applying scripts to some or all of the pages you visit. I have GM scripts that disable google-analytics downloads (because they slow things down), and which disable google-click-tracking on google result pages (because it bothers me that they are doing that).

Here is my google-click disable script:

// ==UserScript==
// @name           Google Clk
// @namespace      googleclk
// @description    Disable Google click tracking
// @include        http://*google.com/*
// ==/UserScript==
// Override google's clk() function, which reports all clicks back to google
unsafeWindow.clk = function(url) {} // { alert(url); } // I use this to test.

By doing something similar with XMLHttpRequest (and other functions) you can effectively disable them. Of course, you may completely break the page by doing this, but you already knew that.

Peter Rowell
A: 

No more than you can disable any other function - there may be some kludges or hacks to be found that could interfere with or break javascript, but we would hope not to find such vulnerabilities.

I'll take a wild stab in the dark and guess that you're trying to stop Ajax in untrusted user input of some kind? Your best bet in that case would be to avoid over-specifying your search parameters by mentioning Ajax, rather, search for 'sanitize javascript', 'user javascript safe'... that kind of thing.

JoeBloggs
A: 

You can replace the browser tool to make AJAX (XMLHttpRequest object) with your own that does nothing.

XMLHttpRequest = function(){}
XMLHttpRequest.prototype = {
    open: function(){},
    send: function(){}
}

Be sure that your replacement code executes before any AJAX call.

This will work for any browser that implement AJAX through the XMLHttpRequest object but will not work for IE. For IE, you may have to overload the CreateObject() function if possible...

Vincent Robert
A: 

Additionally to the Firefox suggestion, you can do it in IE as a side-effect of disabling ActiveX. Also on IE7+ you have to disable the ‘Native XMLHttpRequest’ option.

bobince
+1  A: 

This is a late comment on a question that has already been answered, but for the benefit of people coming in from Google:

With the Tab Permissions extension for Firefox you can disable JavaScript for a particular tab (as opposed to globally for all tabs) with a right-click context menu. I configured the "Permissions" menu item to toggle "Redirect" and "JavaScript," so if I stumble onto a page that has annoying refreshes and AJAX, I can quickly and easily shut down the bandwidth activity of the misbehaving tab without affecting the JavaScript on my other open tabs.