我想在新标签页中提交表单,然后将提交重定向提交到另一个页面。 (不需要回复)
HTML
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
</head>
<form action="my url" name="myForm" id="myForm" target="_blank">
-------
------
</form>
的jQuery
<script type="text/javascript">
$(function() {
$.ajax({
type: $('#myForm').attr('method'),
url: $('#myForm').attr('action'),
data: $('#myForm').serialize(),
success: function(){
alert("success");
//redirect to another page
}
});
});
</script>
我没有任何按钮。有很多例子,但它们都不适合我。
更新:问题是我的表单没有提交。我用来提交数据的表单网址,“我的网址”是一个付款页面网址。
答案 0 :(得分:0)
$(function() {
$.ajax({
type: $('#myForm').attr('method'),
url: $('#myForm').attr('action'),
data: $('#myForm').serialize(),
success: function(){
alert("success");
//redirect to another page
window.open(
'www.google.com',
'_blank' // <- This is what makes it open in a new tab.
);
}
});
});
答案 1 :(得分:0)
如果成功对您不起作用,请尝试使用error
$.ajax({
type: $('#myForm').attr('method'),
url: $('#myForm').attr('action'),
data: $('#myForm').serialize(),
success: function(){
alert("success");
}
error: function(e){
console.log(e);
}
});