我已经检查过这里,并没有这些解决方案在这里解决我的问题。 我似乎无法得到preventDefault()的工作。下面的代码:防止默认不起作用
的Jquery:
$("#changepassword").submit(function(event) {
event.preventDefault(); // stop normal form submission
$.ajax({
url: "changePassword.php",
type: "POST",
data: $(this).serialize(), // you also need to send the form data
dataType: "html",
success: function(html) {
$("#s-window").append(html);
}
});
});
HTML:
<div id="s-window">
<form id="changepassword" action="changePassword.php" method="POST">
<input type="password" name="currentPassword" placeholder="Current Password"/>
<input type="password" name="newPassword" placeholder="New Password"/>
<input type="password" name="confirmPassword" placeholder="Confirm Password"/>
<input class="button" type="submit" value="Change Password" />
</form>
</div>
有我的conosle没有错误。 changePassword.php按照它应该的方式工作。但不是更新我的#s-window,而是将我重定向到changePassword.php页面
我该如何重新编码这个以使所有事情都发生在页面上?
为什么不删除'如果你正在使用AJAX反正form'属性。 –
主要是因为我不知道我在做什么。我可以做到这一点,如果它会工作?你有什么可以解释为什么我会做出这些改变? –
看,你的代码反正通过ajax调用相同的php方法。所以'action'属性的形式是没用的。尝试从form标签中移除'action'和'method'。 –