此請求的內容每天都會發生變化:問題在於瀏覽器(確定爲IE和Chrome)總是顯示舊的結果(首先得到),直到我清除緩存爲止!強制瀏覽器重新讀取ajax結果
我該如何解決這個問題?
$('#q').keyup(function(){
var param = $(this).val();
if(param == ''){
return
}
if(param != ''){
$('#p_a').html('');
}
$.ajax({
url: 'ajax.php',
data: {qty: param},
type: 'GET',
success: function(result){
$('#p_a').html(result);
},
error: function(result){
$('#p_a').html('Error');
},
});
});
PHP:
<?php
if(isset($_GET['qty'])){
$cq = $_GET['qty'];
$cq = $link->real_escape_string($cq);
$GetP = $link->query("CALL GetPrice($cq)") or die('Query Error');
if(mysqli_num_rows($GetP) === 1){
while($p = mysqli_fetch_array($GetP)){
echo $p['values'];
echo $p['dates'];
}
}else{
echo 'More Rows';
}
}
?>
編輯:
這是jQuery的功能/右/最佳/良好的工作解決方案嗎?從documentation:
cache (default: true, false for dataType 'script' and 'jsonp') Type: Boolean If set to false, it will force requested pages not to be cached by the browser. Note: Setting cache to false will only work correctly with HEAD and GET requests. It works by appending "_={timestamp}" to the GET parameters. The parameter is not needed for other types of requests, except in IE8 when a POST is made to a URL that has already been requested by a GET.
將'cache:false'添加到發送到'.ajax()'調用的參數中。你最好在PHP中適當地設置'Cache'頭部,但這是一個不同的問題。 – 2013-07-19 01:52:04