我这里有一个接受用户凭证的表格.如果用户具有无效的用户凭据,则不会加载该页面,但是如果他或她具有有效的凭据,则我希望该页面执行全页面刷新,我将如何实现?我尝试添加.
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>
但页面未重新加载.
解决方法:
在成功函数中,您可以使用JavaScript方式重新加载:
location.reload();
有点像这样
$('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,
//login success
success : function(data) {
//... your other code
location.reload(); //reload the page on the success
}
});
})
这意味着登录失败时,查询会显示错误,因此成功函数中不会出现该错误.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。