简体   繁体   English

jQuery + Ajax-在新选项卡中提交表单后重定向,没有按钮

[英]jquery + ajax - redirect after submit form in new tab with no button

I want to submit my form in new tab and after the submit redirect to another page. 我想在新标签页中提交表单,然后将提交重定向到另一个页面。 (response not required) (不需要回复)

HTML 的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 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>

I don't have any buttons. 我没有任何按钮。 There are many examples, but none of them works for me. 有很多例子,但是没有一个适合我。

UPDATE: The problem is that my form doesn't submit. 更新:问题是我的表单未提交。 The form url I am using to submit the data, "my url" is a payment page url. 我用来提交数据的表格网址,“我的网址”是付款页面的网址。

$(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.
);
}  
});
});

If success doesn't work for you, try with error 如果成功不适合您,请尝试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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM