$.ajax({
url: "data.php"
}).done(function(data) {
//code
});
「data.php」ファイルに新しいデータがある場合にのみ AJAX 呼び出しを設定する、最速で低コストのサーバー メソッドはどれですか? 元。setInterval
このリクエストがいつ完了したかを確認し、別のリクエストを送信しない方法。古いものが完成していないときは?
ajaxリクエストの処理中に「読み込み中...」ステータスを表示しますか?
<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>