0

このリクエストの内容は毎日変化します。問題は、キャッシュをクリアするまで、ブラウザー (確かに 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.

4

1 に答える 1

2

呼び出しで設定するかcache: false$.ajax()特定のページのすべてのリクエストにキャッシュを適用する場合は、次のいずれかを実行できます。

$.ajaxSetup({ cache: false });

_=32409035094これにより、名前付きパラメーターであるクエリ文字列_と現在のタイムスタンプの値が追加されます。これにより、一意のリクエスト文字列が作成され、キャッシュではなくサーバーからリクエストが読み取られます。

于 2013-07-19T02:02:37.217 に答える