[英]window.location.replace not working
我已经写了一个javascript函数,可以发布表格并重定向到主页。 我正在使用window.location.replace转到主页。 但是该函数不是替换url,而是将url附加在当前url的前面。 有什么问题?
$('#submit_fourth').click(function () {
// send data to server to save in table dbo.aspnet_Users =================================================
var firstname = $("#firstname").val();
var lastname = $("#lastname").val();
var username = $("#username").val();
var password = $("#password").val();
var email = $("#email").val();
$.post("/Account/Register", { FirstName: firstname, LastName: lastname, UserName: username, Password: password, ConfirmPassword: password, Email: email });
//send information to server
alert('Congratulations! Your account has been sucessfully created.');
//get back to the login screen
window.location.replace("dgsmart/Central/Login");
单击注册按钮后,当前网址为184.180.25.240/dgsmart/account/register
我假设您正在使用表单onsubmit事件来调用某些函数,如果这样做,则必须通过返回false来防止默认行为; (例如)
window.location.replace("absolute-address"); /*window.location.replace('http://example.com/#' + initialPage); */
return false; //prevent the default behavior of the submit event
您还可以使用此代码设置理想的网址...
<script>
location.href='RegisterNew.php';
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.