2014-12-22 33 views
-3

我有一個購物車頁面。我想要得到的信息對我customter.i有一個提交按鈕我想在提交後重定向到新頁面

<input type="button" id="submit-cart" value='Submit' onclick="submit_cart()" /> 

我想提交表單的onclick後重定向到新的一頁。

+4

你花時間研究/搜索了嗎?有很多方法可以做到這一點。 –

+0

Chris Coyier最近剛發佈了這個:http://css-tricks.com/redirect-web-page/ – philtune

+0

在你處理表單提交的同一個地方做這件事,無論是服務器端,JS,w /即處理完表單後,您可以使用JS,PHP,w/e重定向。 – mopo922

回答

0

使用window.location = url重定向

因此,這看起來像

function submit_cart() { 
    var url = 'xyz.com' // Some url you want to redirect to 
    window.location = url; 
} 

在PHP中,你可以做到這一點通過使用header功能:

<?php 
    header('Location: xyz.com'); // xyz.com is the url you want to redirect to 
    exit(); 
?> 
0
function submit_cart() { 

/* do something amazing you always wanted to do with the user's data */ 
window.location.assign('/* here comes the url the user should be sent to */'); 
} 

或者,無javascript在全部:

<form action = "url to redirect to" method="<!-- POST/GET -->"> 
    <input type="text" name="textinput"/> 
    <input type="submit" class="button" id="submit-cart" value='Submit'/> 
</form>