我的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
fordataType
'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/