如何更改$ .ajax()默认设置?

时间:2022-12-03 22:58:17

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

如何修改$ .ajax()函数的选项的默认值?

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.

允许我同步执行.post()。

2 个解决方案

#1


25  

You want ajaxSetup

你想要ajaxSetup

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

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

#2


21  

Try using $.ajaxSetup()

尝试使用$ .ajaxSetup()

$.ajaxSetup({
  async: false
});

#1


25  

You want ajaxSetup

你想要ajaxSetup

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

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

#2


21  

Try using $.ajaxSetup()

尝试使用$ .ajaxSetup()

$.ajaxSetup({
  async: false
});