gpt4 book ai didi

javascript - jQuery 重定向太慢

转载 作者:行者123 更新时间:2023-12-03 02:50:17 24 4
gpt4 key购买 nike

jQuery 重定向速度太慢,无法连接另一个页面。我尝试过window.location.replacewindow.location.hrefwindow.location。有什么办法可以让重定向更快吗?

<form role="form" id="add_name"  method="post"  enctype="multipart/form-data" action="">
<div class="form-group modal-form">
<input type="text" class="form-control" id="email_id" name="email_id">
</div>
<div class="form-group modal-form">
<input type="text" class="form-control" id="contact" name="contact" >
</div>
<button type="submit" class="btn btn-popup" name="submit" id="submit">save</button>
</div>
</div>
</form>
<script>
$("form#add_name").submit(function(e) {
e.preventDefault();
var formData = new FormData(this);
$.ajax({
url: "device_process.php",
type: 'POST',
data: formData,
success: function(data) {
window.location = "thankyou.php";
},
cache: false,
contentType: false,
processData: false
});
});
</script>

最佳答案

这可能是因为您的服务器端代码可能需要一些时间来处理请求。在这种情况下,最好添加一个进度加载器来通知用户他们的请求正在进行中。它很容易实现。尝试下面的代码。这会起作用。希望这可以帮助。谢谢

body 内部:

<div id="loading" style="display: none;"><div>Loading, Please wait...</div></div>

CSS:

#loading {
position: fixed;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
top: 0;
left: 0;
background-color: #DBDBDB;
opacity: .9;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=90)";
filter: alpha(opacity=90);
z-index: 99999;
display: none;
}

#loading>div{
position: fixed;
top: 50%;
left: 50%;
margin-left: -102px;
width: 205px;
height: 60px;
text-align: left;
background: url('../img/loading.gif') no-repeat; //add a loader image to your local
margin-top: -30px;
padding: 8px 0 0 35px;
}

JS:

$(document).ajaxStart(function () {

$("#loading").fadeIn();

}).ajaxStop(function () {

$("#loading").fadeOut();

$(document).foundation();

});

关于javascript - jQuery 重定向太慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47899847/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com