$ .ajax()之间的区别;和$ .ajaxSetup(); [英] Difference between $.ajax(); and $.ajaxSetup();

查看:86
本文介绍了$ .ajax()之间的区别;和$ .ajaxSetup();的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery中的$.ajax();$.ajaxSetup();之间有什么区别,如下所示:

What is the difference between $.ajax(); and $.ajaxSetup(); in jQuery as in:

$.ajax({
    cache:false
});

$.ajaxSetup({
    cache:true
});

还有,哪个是最好的选择?

Also, which one is best option?

推荐答案

以下内容将防止将来所有将来的AJAX请求被缓存,无论您使用哪种jQuery方法($ .get,$. ajax等)

The following will prevent all future AJAX requests from being cached, regardless of which jQuery method you use ($.get, $.ajax, etc.)

$(document).ready(function() {
  $.ajaxSetup({ cache: false });
});

您应该使用$ .ajax,这将允许您关闭该实例的缓存:

you should use $.ajax, which will allow you to turn caching off for that instance:

$.ajax({url: "myurl", success: myCallback, cache: false});

这篇关于$ .ajax()之间的区别;和$ .ajaxSetup();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆