开发者社区> 问答> 正文

JQuery中ajax如何缓存引入的js文件

有如下代码

$.ajax({

type: "GET",
cache: true,
url: 'aa.php',
dataType: "html",
success: function (res) {
$('.page-loading').remove();
$('.page-content .page-content-body').html(res);

});
发现 请求为
aa.com/aa.php
aa.com/aa.css
aa.com/aa.js?_=1373600904652

这样好像 js 文件不被缓存
请问有没有方法去掉 _=1373600904652 ???

展开
收起
a123456678 2016-07-29 11:24:39 2204 0
1 条回答
写回答
取消 提交回答
  • 昨晚研究了下这个问题,知道怎么回事了,在你的 ajax 请求前加一段代码:

    $.ajaxSetup({
    cache: true
    });
    同时你的那句 cache: true 可以省略,因为默认就是 cache: true,只有 dataType 为 "script" 和 "jsonp" 时 cache 默认为 false。你在此处加的 cache: true 其实只影响了 aa.php 的缓存与否。

    2019-07-17 20:01:44
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
JavaScript面向对象的程序设计 立即下载
Delivering Javascript to World 立即下载
编程语言如何演化-以JS的private为例 立即下载