Clearinteval不起作用

时间:2015-10-29 11:35:38

标签: javascript

Clearinterval在成功条件下不起作用 代码就像:

var threadComplete;
    function doc_creation() {
                $.ajax(
            {
                type: "POST",
                url: '@Url.Action("generateDoc")',
                dataType: "json",
                mtype: "post",
                async: true,
                success: function (data) {
                    console.log("show modal");
                    threadComplete = setInterval(function () { checkDocGen() }, 3000);
                }
            });
        }
            function checkDocGen() {
                $.ajax(
            {
                type: "POST",
                url: '@Url.Action("callThreadSleep")',
                dataType: "json",
                mtype: "post",
                async: true,
                data: { ids: download_id },
                success: function (data) {
                    debugger;     //   clearInterval(threadComplete); If i put here then it works        
                    if (data != true) {
                        clearInterval(threadComplete); //it executes but still call threadcomplete
                        console.log("hide");
                        if (data == "") {
                            $("#alert_doc_err").slideDown().delay(5000).slideUp();
                        } else {
                            window.location.href = data;
                        }

但是,如果我将clearInterval()成功地放在第一行,它会起作用。任何想法或任何改变?

0 个答案:

没有答案