12

How can I modify the default values of options for the $.ajax() function?

Ideally to do something similar to:

//set ajax async to false
$(someSelector).load(url, data, function(){});
//set ajax async to true

to allow me to carry out .post() synchronously.

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
StuperUser
  • 10,555
  • 13
  • 78
  • 137
  • 2
    **Note to all:** Synchronous XMLHttpRequest on the main thread is deprecated. Do not use this approach. – Raptor Mar 06 '17 at 06:42

2 Answers2

26

You want ajaxSetup

 $.ajaxSetup({
   url: "/xmlhttp/",
   global: false,
   type: "POST"

 });
 $.ajax({ data: myData });
Joe
  • 80,724
  • 18
  • 127
  • 145
22

Try using $.ajaxSetup()

$.ajaxSetup({
  async: false
});
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
  • 2
    Doing this gave me the following message: Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/. – patrick Jul 11 '15 at 09:41