简体   繁体   English

如何在另一个函数中调用setinterval函数不起作用

[英]How to call setinterval function in another function is not working

I want to display Updated records count when Ajax process is going on. 我想在Ajax进程正在进行时显示更新的记录计数。 When i click on start process button updateRecords()function will execute and it will update records status from open to waiting status one by one in database.So at the same time i want display the waiting records count .For this when user click on strat process button i want to call displayWaitingRecords() using setinterval. 当我单击开始进程按钮时,updateRecords()函数将执行,它将在数据库中将记录状态从打开状态一一更新为等待状态。因此,同时我想显示等待记录数。为此,当用户单击strat时进程按钮,我想使用setinterval调用displayWaitingRecords()。

I am calling that function like this from updateRecords() 我从updateRecords()这样调用该函数

clear_Process = setInterval(function(){displayWaitingRecords()},200);

But displayWaitingRecords() will not call until updateRecords() process completes.But my requirement is displayWaitingRecords() also will execute simaltaniously with updateRecords() . 但是displayWaitingRecords()updateRecords()过程完成之前不会调用。但是我的要求是displayWaitingRecords()也将与updateRecords()同时执行。

Function to display updated record count 显示更新记录数的功能

function displayWaitingRecords()
{
    jQuery.ajax({
        type: 'GET',
        crossDomain:true,
        async: false,
        url: "/curlRRQCount.php",
        success: function(count){
            if(count)
            {
                jQuery("#processed_poids_div").html("Processed Order ids:"+count) ;
            }                 
        }
    });  
}

Function when i click on start process button 单击开始过程按钮时的功能

var clear_Process = "";
function updateRecords()
{
    clear_Process = setInterval(function(){displayWaitingRecords()},200);  
    var str = jQuery("#rrq_form :input[value!='']").serialize();
    jQuery.ajax({
        async: false,
        type: 'POST',
        data : str,
        url: "/updaterecord_status.php",
        success: function(valid_result)
        {
            if(jQuery.trim(valid_result) == 'Success')
            {
                jQuery("#rrq_load_img").hide();
                jQuery("#rrq_orders_status").html("some success message");
            }
        }
    }); 
}

Where i am doing wrong? 我在哪里做错了? Any help would be greatly appreciated. 任何帮助将不胜感激。

You have set async: false . 您已经设置了async: false So the ajax call will process synchronized. 因此,ajax调用将同步处理。 Set it to false or leave it out (because true is default): 将其设置为false或不设置(因为默认为true):

var clear_Process = "";
function updateRecords()
{
    clear_Process = setInterval(function(){displayWaitingRecords()},200);  
    var str = jQuery("#rrq_form :input[value!='']").serialize();
    jQuery.ajax({
        async: true,
        type: 'POST',
        data : str,
        url: "/updaterecord_status.php",
        success: function(valid_result)
        {
            if(jQuery.trim(valid_result) == 'Success')
            {
                jQuery("#rrq_load_img").hide();
                jQuery("#rrq_orders_status").html("some success message");
            }
        }
    }); 
}

If you leave it out you have the same result: 如果忽略它,您将得到相同的结果:

function displayWaitingRecords()
{
    jQuery.ajax({
        type: 'GET',
        crossDomain:true,
        url: "/curlRRQCount.php",
        success: function(count){
            if(count)
            {
                jQuery("#processed_poids_div").html("Processed Order ids:"+count) ;
            }                 
        }
    });  
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM