问题描述
在jQuery中,我可以使用ajaxSetup设置ajax默认参数,例如:
In jQuery I can set ajax default parameters with ajaxSetup like:
$.ajaxSetup({'async': false});
是否可以阅读它们?这样,对于上面的示例,我知道当前是否将异步设置为false
或true
?
Is it possible to read them? So that for the example above I knew if async is currently set to false
or true
?
推荐答案
您可以执行$.ajaxSetup()['cache']
,但请不要这样做.不鼓励使用ajaxSetup
,因为随着应用程序的增大,这可能会导致行为异常,因为每个Ajax调用都将取决于应用程序的状态,从而导致不可预测性.
You can do this $.ajaxSetup()['cache']
, but please don't. The use of ajaxSetup
is not encouraged, this may lead to misbehavior as your application grows bigger, because each Ajax call would depend on the state of your application, which leads to unpredictability.
如果确实需要ajax的默认选项,则可以尝试使用$.extend
将当前选项与某些方法调用返回的默认选项合并.至少您可以调试并查看将哪些参数传递给您的请求.
If you really need default options for ajax, you could try using $.extend
to merge your current options with the default options returned by some method call.. maybe some object injected through requireJs
maybe. At least you can debug and see which params are being passed to your request.
这篇关于如何读取jQuery中的默认Ajax参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!