2013-07-15 141 views
-1

我使用Ajax将表单数据提交到另一个页面,然后将浏览器重定向到该页面。这是我正在使用的代码:发送POST和GET请求的Ajax请求

$(".step").submit(function(e){ 
     e.preventDefault(); 
     $.ajax({ 
      url: "/dashboard/step2/", 
      type: "post", 
      data: paramObj, 
      success: function(response){ 
       console.log(response); 
       window.location.href="/dashboard/step2/"; 
      } 
     }); 
    }); 

但是,此代码发送POST和GET请求。这会导致其他问题,因为我有其他函数依赖于唯一发送的请求是POST请求的事实。任何想法或建议?

+0

什么问题呢它导致?它应该如何表现? – FakeRainBrigand

+0

我有另一个函数,当GET请求发送时退出 –

回答

3

这是造成GET,因为你告诉浏览器导航到/仪表板/第二步/通过发出命令window.location.href="/dashboard/step2/";

+0

我知道。我想要做的是重定向到该页面,而不明确指定 –

+0

那么,为什么你使用AJAX?浏览器完全能够将表单数据发布到没有javascript的URL。 –

+0

我正在从多个表单提交数据提交到其他页面运行其他功能 –

0

提交表单ajax success后是这样的:

$(".step").submit(function(e) { 
    var form = $(this); 
    if (form.data('success') != '1') { // run this if ajax call is not completed 
     e.preventDefault(); 
     $.ajax({ 
      url: "/dashboard/step2/", 
      type: "post", 
      data: paramObj, 
      success: function(response) { 
       form.data('success', '1'); 
       $(".step").submit(); 
      } 
     }); 
    } 
});