此请求的内容每天都在变化:问题是浏览器(肯定是 IE 和 Chrome)总是显示旧结果(第一次获取),直到我清除缓存!
我该如何解决这个问题???
$('#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 函数是一个/正确/最好/好的工作解决方案吗?从文档中:
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.