$.ajax({
url: "data.php"
}).done(function(data) {
//code
});
这是只有在“data.php”文件中有新数据时才设置AJAX调用的最快且最低服务器方法?恩。的setInterval
如何检查此请求何时完成,而不是发送另一个请求。什么时候旧的不完整?
在ajax请求进行处理时显示“loading ...”状态?
答案 0 :(得分:0)
<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>