我有这样的代码:为什么我在变量的末尾有随机字符串?
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
$(document).ready(function(){
var j = jQuery.noConflict();
j(document).ready(function() {
setInterval(function(i) {
var divs = document.getElementsByClassName('post');
var lastPostID = parseInt(divs[0].getAttribute('data-id'));
var myurl = "/post/"+parseInt(lastPostID);
console.log(myurl, "myurl");
j.ajax({
url: myurl,
cache: false,
success: function(html){
j("#temp").html(html)
j("#temp").prependTo("#allPosts");
}
})
}, 5000)
});
});
</script>
</head>
<body>
<div id="temp" style="display: none;"></div>
<div id="allPosts">
<div class='post' data-id='100'>...</div>
<div class='post' data-id='20'>...</div>
<div class='post' data-id='1'>...</div>
</div>
</body>
</html>
我看到控制台每5秒:
/post/100 myurl jQuery_div_update.html:12
OPTIONS file:///post/100?_=1392319636208
在第一行(console.log...
)是URL确定。
但jQuery使用的URL(url: myurl,...
)末尾有“?_ = 1392319636208”。为什么有随机字符串?我怎样才能删除它?
这是因为'缓存:FALSE' –
jQuery的增加它会阻止缓存。 –
这是为了避免缓存,但发布请求不应该缓存,所以它没有区别。 'cache:false' < - – epascarello