-3
$.ajax({
    url: "data.php"
}).done(function(data) { 
    //code
});
  1. 「data.php」ファイルに新しいデータがある場合にのみ AJAX 呼び出しを設定する、最速で低コストのサーバー メソッドはどれですか? 元。setInterval

  2. このリクエストがいつ完了したかを確認し、別のリクエストを送信しない方法。古いものが完成していないときは?

  3. ajaxリクエストの処理中に「読み込み中...」ステータスを表示しますか?

4

1 に答える 1

1
<script type="text/javascript"> 
var inProcess = 0;
function get_new_stuff() {
    if (inProcess == 0) {
        inProcess = 1;
        $.ajax({
            type: 'POST', //or GET
            dataType: "json", //or html, text
            url: 'data.php',
            data: '',
            beforeSend: function() {
                // please wait... message
            },
            success: function (data) {
                // returned data
                inProcess = 0;
            },
            error: function (jqXHR, textStatus, errorThrown) {
                // on error
                inProcess = 0;
                alert(textStatus + ": " + errorThrown);
            },
            cache: false
        });
    }
}

setTimeout(get_new_stuff, 10000);
</script>
于 2013-09-30T13:41:33.760 に答える