javascript - 一个随机数自动附加到一个js文件

标签 javascript jquery html caching

我的index.php代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script src="js/jquery.js"></script>
<script>
$(function(){
$("body").load("AJAX.php");
});</script></head>
<body>
</body>
</html>

还有我的 AJAX.php 代码

<body>
<script src="js/asdf.js"></script>

</body>

和我的 asdf.js 代码

function cool(){
    alert("hi");}

现在当我加载 index.php 并看到它输出的控制台时

[16:21:57.237] GET http://localhost/js/asdf.js?_=1342003917230 [HTTP/1.1 200 OK 8ms]

现在我想知道为什么它会将该随机数添加到 js 文件的 url 以及如何防止这种情况发生?

最佳答案

参见 the docs for the ajax method :

cache

Default: true, false for dataType 'script' and 'jsonp'

If set to false, it will force requested pages not to be cached by the browser. Setting cache to false also appends a query string parameter, "_=[TIMESTAMP]", to the URL.

关于javascript - 一个随机数自动附加到一个js文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11431104/

相关文章:

javascript - 基本的 jQuery 问题

javascript - Ajax成功功能好像不起作用

jquery - 检查是否选择了第一个选项

jquery - 选择行时如何从所有相同级别的表行中删除 CSS 类?

html - 调整大小时如何自动将框移动到底部?

javascript - 从串联函数谷歌脚本中删除不需要的分隔符

javascript - 如何在 Google Maps v3 API for Directions 中更改开始和结束标记图像

javascript - iPad 不显示来自 javascript 的图像

jquery - 在滚动条上运行 jQuery 数字计数器

html - 选择具有 CSS 样式的第三个 div 的链接 (a)