我有這樣的代碼:爲什麼我在變量的末尾有隨機字符串?
<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