[英]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.