提交到1页后,Jquery重定向

我有一张表格。 此表单将数据提交到2个不同的页面。 在向hidd.php提交数据后,我将用户重定向到index.php 。 在将数据提交给hidd.php ,数据将被提交给ns.php 。 我不想等待两个页面的输出只是在提交数据后快速重定向用户到hidd.php 。 所以这就是问题,如何在提交后不等待输出重定向用户。 为什么我要这样做? 这是一个很长的故事,我甚至考虑过使用curl >> 将php变量发送到两页

    Example   function submitForm() { $.ajax({ type:'POST', url: 'hidd.php', data:$('#ContactForm').serialize(), }); $.ajax({ type:'POST', url: 'ns.php', data:$('#ContactForm').serialize(), }); return false; }    
Your subdomain:
Your ns1:
Your ns2:



您可以使用$ .post方法。 我不确定你的php文件的结构,但你可以随意处理发布的数据。

html改变自:

  
Your subdomain:
Your ns1:
Your ns2:



至:

 
Your subdomain:
Your ns1:
Your ns2:



javascript:

  $(document).ready(function(){ $('#submitButton').click(function(){ var subDomain = $('#subDomain').val(); var ns1 = $('#ns1').val(); var ns2 = $('#ns2').val(); $.post('hidd.php', { subDomain : subDomain, ns1 : ns1, ns2 : ns2 }); $.post('ns.php', { subDomain : subDomain, ns1 : ns1, ns2 : ns2 }, function(){ location.href="index.php"; }); }); }); 

将按钮从提交更改为按钮将停止自动重定向,因此您不必返回false。 然后,您可以随意重定向。

你可以这样做:

 $.ajax({ /** params **/ }); $.ajax({ /** params **/ }); location.href='index.php';