我正在尝试提交一个表单,打开一个将接收数据的新页面,而当前页面将返回到索引。
这是我尝试做的:
<form method="post" action="newpage.php" target="_blank" onsubmit="location.replace('index.php')">
//inputs
<input type=image src="image.jpg" alt="Send" value=submit />
</form>
所以我想让它做的是在新选项卡中打开 newpage.php,然后在当前选项卡中打开 index.php,但它似乎无法那样工作。 我也尝试添加
onclick="location.replace('index.php')
到我的提交输入,但它也不起作用。
有办法吗? 谢谢
最佳答案
//If you want to use Ajax + jQuery:
var fromData = $(#formID).serialize(); // your form's data
$.ajax({
type: "POST",
url: "newpage.php",
data: fromData //sends the data to the new page.
})
.done(function( msg ) {
window.location.href = 'index.php' // redirects the page when finished.
});
关于javascript - 提交表单并更改页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20668367/