该页面不会停止重新加载。我怎么能阻止它?
$(function() {
var canSubmit = localStorage.getItem("can_submit");
if(!canSubmit) {
document.forms['myForm'].submit();
localStorage.setItem("can_submit","1");
window.location.reload();
}
localStorage.removeItem("can_submit");
});
答案 0 :(得分:0)
提交表单会重新加载页面,并停止其余的Javascript。您应该在提交之前更新本地存储。并且调用window.location.reload()
没有意义,因为提交表单会重新加载表单返回的内容。
$(function() {
var canSubmit = localStorage.getItem("can_submit");
if(!canSubmit) {
localStorage.setItem("can_submit","1");
document.forms['myForm'].submit();
}
localStorage.removeItem("can_submit");
});
答案 1 :(得分:0)
$(function() {
var canSubmit = localStorage.getItem("can_submit");
if(!canSubmit) {
localStorage.setItem("can_submit","1");
document.forms['myForm'].submit();
}else{
localStorage.removeItem("can_submit");
}});
答案 2 :(得分:0)
这项工作对我来说没有重新加载并重定向到行动页面
$("#myForm").submit(function () {
var nameValue = $('#Name').val();
var emailValue = $('#Email').val();
var phoneValue = $('#Phone').val();
var subjectValue = $('#Subject').val();
var messageValue = $('#Message').val();
$.post('YourActionUrl', { Name: nameValue, Email: emailValue, Phone: phoneValue, Subject: subjectValue, Message: messageValue }, function (data) {
});
$("#myForm")[0].reset();
// make sure you return false to cancel any default actions of this button
return false;
});