Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling ajaxSetup Defaults for some AJAX Calls

Tags:

jquery

ajax

The corporate intranet I built heavily uses AJAX calls to load tables and other resources. By default I have a modal dialog box appear with a loading gif to let the user know the page is loading. I set this default up with jQuery's ajaxSetup.

There are a couple of areas where I use a search box with autocomplete. And I noticed every time a character is typed the loading dialog box appears. Any way to disable the ajaxSetup for just that call?

Thanks for the help!

like image 271
whobutsb Avatar asked Nov 10 '09 15:11

whobutsb


2 Answers

You should be able to pass a new options object with every ajax call to overwrite the settings in the default when needed.

Not sure if your modal is on beforeSend or what have you, but I think you will get the picture from below.

$.ajax({ beforeSend: function() { /* do nothing */ }....
like image 55
Quintin Robinson Avatar answered Sep 29 '22 11:09

Quintin Robinson


I'm guessing that you set up a handler for a global Ajax event to create the dialog box. These events can be disabled for a specific request like so (from the jQuery documentation):

Global Events

These events are broadcast to all elements in the DOM, triggering any handlers which may be listening. You can listen for these events like so:

$("#loading").bind("ajaxSend", function(){
   $(this).show();
 }).bind("ajaxComplete", function(){
   $(this).hide();
 });

Global events can be disabled, for a particular Ajax request, by passing in the global option, like so:

$.ajax({
   url: "test.html",
   global: false,
   // ...
 });
like image 33
Ryan Lynch Avatar answered Sep 29 '22 13:09

Ryan Lynch