2013-07-30 45 views
0

我正在嘗試爲我的網站創建一個新的登錄頁面,並且我正在使用nodejs創建登錄部分。所以我使用html post方法傳遞參數..所以基本上我有一個簽名部分,註冊部分和忘記密碼部分。我每個形式的行動給路徑/本地,/註冊和/忘記分別..只有一個頁面的主題。所以只有一個索引文件可以處理所有這些功能。所以當我提交這些表格...如果它unsuccesul它會去http://www.mycustomurl/localhttp://www.mycustomurl/signuphttp://www.mycustomurl/local/forgothttp://www.mycustomurl/local/forgot並被重定向到這些網頁..我創建了頁面index.html重複的文件名signup.html,local.html和forgot.html。是否有可能將表單提交重定向到當前頁面?哪種方法最好?HTML POST重定向問題

+0

如果使用單頁的主題,關於使用AJAX如何? –

+0

使用ajax不安全,因爲post請求參數有私人信息,如密碼 – user1371896

+0

雖然您使用表單,但您的表單POST數據仍然可見。 –

回答

1

如果我已經正確理解你的問題,你應該可以用expressJS來做到這一點。您可以設置不同的路線來提供相同的文件。像這樣的東西應該工作。

app.post('local', function(request, response){ 
    //your code that does stuff here 
    //if successful 
     //do your action 
    //if unsuccessful 
     //serve your single page 
     response.sendfile(path_to_file_index); 
}); 

app.post('signup', function(request, response){ 
    //your code that does stuff here 
    //if successful 
     //do your action 
    //if unsuccessful 
     //serve your single page 
     response.sendfile(path_to_file_index); 
}); 

app.post('forgot', function(request, response){ 
    //your code that does stuff here 
    //if successful 
     //do your action 
    //if unsuccessful 
     //serve your single page 
     response.sendfile(path_to_file_index); 
}); 
+0

所以有可能將響應變量傳遞給索引文件?應該nt我們要起訴response.render函數,因爲我們需要顯示變量值,它顯示了註冊錯誤的原因,一旦提交按鈕被點擊,它會轉到corespred url並顯示文件未找到消息 – user1371896

+0

This依靠。如果您使用的是模板引擎,那麼從請求中獲取變量值並將其分配給您的視圖(您的索引文件)就足夠了。如果是這樣的話,我不認爲你會使用'.sendfile'。你可以使用你的模板引擎需要的任何輸出功能。你將無法使用'.sendfile'來完成它。 – JohnP

+1

感謝您的答案..我們正在使用ejs模板..所以它的response.render(path_to_file_index)..我一定會讓你知道上述解決方案是否存在或不... – user1371896

0

重定向通過.htaccess文件是可能的:

RewriteEngine On 
RewriteCond %{HTTP_HOST} !^www.abc.com$ [NC] 
RewriteRule ^(.*)$ http://www.abc.com/$1 [L,R=301] 

OR

RewriteEngine On 
RewriteCond %{HTTP_HOST} !oldexample.com$ [NC] 
RewriteRule ^(.*)$ http://www.newexample.com/$1 [L,R=301]