2016-08-15 91 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");