jQuery AJAX调用函数超时 [英] jQuery AJAX call function on timeout

查看:200
本文介绍了jQuery AJAX调用函数超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重新加载我的jQuery数据表,而不刷新页面以试图捕获新数据。



这是我的初始就绪功能,开始这个过程: / p>

  $(document).ready(function()
{
$ .ajax({
url:'api / qnams_all.php',
type:GET,
dataType:json
})。done(function(response){
console。 log(response.data);
renderDataTable(response.data)
})。fail(function(){
alert(error);
})。 function(){
alert(complete);
});
});

我将数据发送到此功能:

  function renderDataTable(data)
{
var $ dataTable = $('#example1')。DataTable({
data数据,
iDisplayLength:25,
order:[[6,desc]],
bDestroy:true,
stateSave b $ b //还有一些东西,但我不认为有必要显示
});
}

我试图利用这里找到的答案:



但刷新后,它看起来像这样:





上面的图片确实重新加载没有页面清爽,但我不知道为什么它看起来像上面的图片。



请帮我解决这个问题。

解决方案

我认为这个例子将是有用的

  //重新加载表数据30秒(分页重置)
var table = $('#example')。DataTable({
ajax:data.json
});

setInterval(function(){
table.ajax.reload();
},30000);

更多详细信息 - here


I am trying to reload my jQuery DataTables without refreshing the page in an attempt to capture new data.

Here is my initial ready function that begins the process:

 $(document).ready(function()
 {
   $.ajax({
     url:'api/qnams_all.php',
     type:"GET",
     dataType:"json"
   }).done(function(response) {
       console.log(response.data);
       renderDataTable(response.data)
   }).fail(function() {
       alert( "error" );
   }).always(function() {
       alert( "complete" );
   });  
 });

I'm sending the data to this function:

 function renderDataTable(data)
 {
   var $dataTable = $('#example1').DataTable({
     "data": data,
     "iDisplayLength": 25,
     "order": [[ 6, "desc" ]],
     "bDestroy": true,
     "stateSave": true
     // there's some more stuff, but I don't think necessary to show
   });
 }

I'm trying to utilize the answer found here: How to refresh table contents in div using jquery/ajax

As follows:

 setTimeout(function(){
   $( "#example1" ).load( "mywebpage.php #example1" );
 }, 2000);

Using all of the above code, when the page first loads, it looks like this:

But after the refresh, it looks like this:

The picture immediately above does indeed reload without the page refreshing, but I'm not sure why it looks like the picture above.

Please help me fix this.

解决方案

I think this example will be usefull

//Reload the table data every 30 seconds (paging reset)
var table = $('#example').DataTable( {
    ajax: "data.json"
} );

setInterval( function () {
    table.ajax.reload();
}, 30000 );

more details - here

这篇关于jQuery AJAX调用函数超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆