Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 当ajax正在处理且请求尚未完成时,如何显示另一个DIV?_Jquery_Ajax_Asp.net Ajax - Fatal编程技术网

Jquery 当ajax正在处理且请求尚未完成时,如何显示另一个DIV?

Jquery 当ajax正在处理且请求尚未完成时,如何显示另一个DIV?,jquery,ajax,asp.net-ajax,Jquery,Ajax,Asp.net Ajax,有两个Div:contentDiv和progressDiv。我使用ajax以以下方式提交数据。 对于ajax的完成,可能需要很多时间,因为我使用ajax上传不同的数据,包括多个图像,所以ajax完成可能需要15-20秒 当ajax正在进行时,我想向用户显示progressDiv,表明正在进行提交。我试图在不同的地方显示和隐藏div,比如在函数调用时,beforeSendajax函数,成功时,出错时,但问题是progressDiv不显示,contentDiv不隐藏 我应该做哪些更改,以便在处理aj

有两个Div:
contentDiv
progressDiv
。我使用ajax以以下方式提交数据。 对于ajax的完成,可能需要很多时间,因为我使用ajax上传不同的数据,包括多个图像,所以ajax完成可能需要15-20秒

当ajax正在进行时,我想向用户显示
progressDiv
,表明正在进行提交。我试图在不同的地方显示和隐藏div,比如在函数调用时,
beforeSend
ajax函数,成功时,出错时,但问题是
progressDiv
不显示,contentDiv不隐藏

我应该做哪些更改,以便在处理ajax时,向用户显示
progressDiv

 function submitButtonClick() {
        // on button click I inserted timeout function to hide contentDiv and show 
        // progressDiv but these codes don't execute

        setTimeout(function () {
            document.getElementById("progressDiv").style.display = "block";
            document.getElementById("contentDiv").style.display = "none";
        }, 400);

        $.ajax({
            type: "POST",
            url: "Home/SubmitData",
            data: formdata,
            async: false,
            cache: false,
            contentType: false,
            processData: false,
               // on beforeSend function also, I inserted timeout function to hide contentDiv and show 
               // progressDiv but these codes don't execute
            beforeSend: function (xhr, status) {
                document.getElementById("progressDiv").style.display = "block";
                document.getElementById("contentDiv").style.display = "none";
            },
            success: function (xhr) {
                if (xhr.success == true) {
                    setTimeout(function () {
                        document.getElementById("progressDiv").style.display = "none";
                    }, 1500);

                    alert(xhr.messsage);
                    window.location.href = '@Url.Action("Index", "Home")';
                } else {
                    document.getElementById("progressDiv").style.display = "none";
                    document.getElementById("contentDiv").style.display = "block";
                }
            },
            error: function (xhr, ajaxOptions, thrownError) {
                setTimeout(function () {
                    document.getElementById("myprogress1").style.display = "none";
                    document.getElementById("mainwizard").style.display = "block";
                }, 1500);

                alert('Sorry! Error occured while saving data');
            }
        });
   }

成功时,您已将window.location.href设置为主页,在您的页面中,将ajax数据发送到SubmitData页面需要几秒钟的时间,因此您希望能够看到progressDiv显示……将“window.location.href=”@Url.Action(“Index”,“home”);”在setTimeout函数中,查看发生了什么,您可以使用完整函数或发送回调函数作为参数