StuperUser
StuperUser

Reputation: 10850

How to change $.ajax() default settings?

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.

Upvotes: 12

Views: 19119

Answers (2)

Joe
Joe

Reputation: 82624

You want ajaxSetup

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

 });
 $.ajax({ data: myData });

Upvotes: 26

gen_Eric
gen_Eric

Reputation: 227280

Try using $.ajaxSetup()

$.ajaxSetup({
  async: false
});

Upvotes: 23

Related Questions