2016-08-15 55 views
-1

這是我的代碼:如何有形式重定向提交

function mySubmit() { 
    var myForms = document.getElementsByTagName("form"); 
    var userEmail = document.getElementById("myEmail").childNodes[0].nodeValue; 

    for (var t = 0; t < myForms.length; t++){ 
    myForms[t].s_emailaddress.value = userEmail 
    $.post("http://test.test", $(myForms).eq(t).serialize(), function (data, status) { 
     if (status === "success") { 

我想重定向功能添加到這一點。例如,所有形式的數據應該被提交,提交後重定向到www.google.com

+0

對智者說的話,你應該更好地格式化你的代碼。它使您和其他人更容易閱讀和調試它。 –

回答

0
if (status === "success") { 
    window.location = 'https://google.com'; 
} 
+0

請解釋如何回答這個問題。即使問題不存在,一個好的答案應該是獨立的。 – jpaugh

0

一些方法來重定向頁面:

//設置當前窗口的新位置。

window.location = "http://www.google.com"; 

//設置當前窗口的新href(URL)。

window.location.href = "http://www.google.com"; 

//將一個新的URL分配給當前窗口。

window.location.assign("http://www.google.com"); 

//用新的窗口替換當前窗口的位置。

window.location.replace("http://www.google.com");