Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a current value from jQuery's ajaxSetup

Tags:

jquery

I have a page that, at the user's request, opens a dialog box and loads an external file into it using jQuery's load() method.

The external file contains links to scripts (it can work as a standalone page, too) and that's fine, only that jQuery forces those scripts to be loaded (by adding a timestamp) even if they have been loaded already.

I need to tell jQuery to allow caching when it sees these scripts. The answer to a bug report suggests using

$.ajaxSetup({ cache: true })

…which does work, but changes the setting for all future AJAX requests. Is there a way to do something like:

// Get current setting - code not valid but is what I want
var defaultCache = $.ajaxSetup("cache");

$.ajaxSetup({cache:true});  // Now set it to what I want

// do stuff…

$.ajaxSetup({cache:defaultCache});  // Set it back to the default
like image 604
user535673 Avatar asked Aug 08 '12 08:08

user535673


People also ask

How do you check AJAX URL is working or not?

$. ajax({ type: 'POST', url: 'page. php', data: stuff, success: function( data ) { }, error: function(xhr, status, error) { // check status && error }, dataType: 'text' });

Which of the below method will you choose if you want to setup global setting for AJAX?

jQuery ajaxSetup() Method The ajaxSetup() method sets default values for future AJAX requests.

What is data in AJAX?

data : The data to send to the server when performing the Ajax request. dataFilter : A function to be used to handle the raw response data of XMLHttpRequest. dataType : The type of data expected back from the server.


1 Answers

you can do this:

$.ajaxSetup()['cache']
like image 148
YardenST Avatar answered Oct 30 '22 09:10

YardenST