我这里有一个表单,用于接收用户凭证。如果用户凭证无效,则页面不会加载,但是如果他或她拥有有效的凭证,我希望页面进行完整的刷新。我该如何实现呢?我已经尝试添加。
window.location.href = window.location.href;
在响应的html中,但它没有起作用,看起来像是jquery正在删除脚本代码?
这里是表单提交的AJAX代码。
$('body').on('submit', '#sign-in', function(e) {
e.preventDefault();
var data = $(this).serialize();
var url = $(this).attr('action');
$.ajax({
//this is the php file that processes the data and send mail
url : url,
type : "POST",
data : data,
//Do not cache the page
cache : false,
//success
success : function(data) {
alert(data);
$('#loginModal').html($(data).find('#loginModal').html());
}
});
})
如果用户有有效的凭据,成功响应将是这样的。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script>
window.location.href = window.location.href;
</script>
</head>
但是页面没有重新加载。
data
中检查登录是否成功。如果是,则location.reload()
,否则执行任何操作以告知发生错误。 - Hugo Dozois