[英]jquery + ajax - redirect after submit form in new tab with no button
我想在新标签页中提交表单,然后将提交重定向到另一个页面。 (不需要回复)
的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>
我没有任何按钮。 有很多例子,但是没有一个适合我。
更新:问题是我的表单未提交。 我用来提交数据的表格网址,“我的网址”是付款页面的网址。
$(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.
);
}
});
});
如果成功不适合您,请尝试error
$.ajax({
type: $('#myForm').attr('method'),
url: $('#myForm').attr('action'),
data: $('#myForm').serialize(),
success: function(){
alert("success");
}
error: function(e){
console.log(e);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.