dongzi1209 2014-11-18 04:04
浏览 46

clearInterval()在php中的ajax中工作,并且在提交时调用了get和post方法

I am using setInterval and then unable to clearInterval in my code. Please see the code I am getting the value of complete and it is true and also entering the if statement but clearInterval still not working. I am tired and trying for last 10 hours but not find the bug. I checking the console.log and it is not stopping the interval.

jQuery(document).ready(function() {
    var complete = false;
    var Interval;

    jQuery( "#form" ).submit(function() {
        Interval = setInterval(get, 100);
        post();
        return false;
    });

    function post(){

        var url = "my/url/here";

        var data = {
        'action': 'action/here',
        'name': 'value'
        };
        jQuery.post(url, data, function(response) {
            jQuery("#emails").html(response);
        }).done(function() {
        //alert( "second success" );
        })
        .fail(function() {
        //alert( "error" );
        })
        .always(function() {
         complete = true;   
        //alert( "finished" );
        });

    } // End post()
    function get(){

        var url = "url/goes/here";

        if(complete == true){
            clearInterval(Interval);
        }
        var data = {
            'action': 'action/here',
        };

        jQuery.get(url, data, function(response) {
            console.log(response);
            jQuery("#progress").html(response);     
        });

    } // End get()

});

here is the original code below. ajax call is working fine but clearInterval() not working

<script type="text/javascript" >
jQuery(document).ready(function() {

    jQuery(".juee_emails_row").hide();

    var juee_complete = false;
    var juee_Interval;

    jQuery( "#juee_form" ).submit(function() {
        jQuery(".juee_emails_row").show();
        juee_Interval = setInterval(juee_get, 100);
        juee_post();
        return false;
    });

    function juee_post(){
        var data = {
        'action': 'juee_get_emails',
        'juee_data_option': jQuery('input[name=juee_data_option]:checked', '#juee_form').val()
        };
        jQuery.post(ajaxurl, data, function(response) {
        jQuery("#juee_emails_td").html(response);
        }).done(function() {
        //alert( "second success" );
        })
        .fail(function() {
        //alert( "error" );
        })
        .always(function() {
         juee_complete = true;  
        //alert( "finished" );
        });

    } // End juee_post()
    function juee_get(){
        if(juee_complete == true){
            clearInterval(juee_Interval);
        }
        var data = {
            'action': 'juee_progress',
        };

        jQuery.get(ajaxurl, data, function(response) {
        console.log(response + " email found");
        jQuery("#juee_progress_td").html("");
        jQuery("#juee_progress_td").html(response);     
    });

    } // End juee_get()

});
</script> 
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
    • ¥20 关于URL获取的参数,无法执行二选一查询
    • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
    • ¥15 marlin编译错误,如何解决?
    • ¥15 有偿四位数,节约算法和扫描算法
    • ¥15 VUE项目怎么运行,系统打不开
    • ¥50 pointpillars等目标检测算法怎么融合注意力机制
    • ¥20 Vs code Mac系统 PHP Debug调试环境配置
    • ¥60 大一项目课,微信小程序
    • ¥15 求视频摘要youtube和ovp数据集