从ajax div重新加载php页面

从ajax div重新加载php页面,php,ajax,jquery,Php,Ajax,Jquery,我使用带有Jquery选项卡的页面,如果我提交选项卡中的一个表单,则仅提交该选项卡,并使用此Jquery代码刷新该选项卡: $(document).on("submit", "#plaatsen_stap3", function(event) { /* stop form from submitting normally */ event.preventDefault(); $.ajax({ type:"GET", url:"../plaat

我使用带有Jquery选项卡的页面,如果我提交选项卡中的一个表单,则仅提交该选项卡,并使用此Jquery代码刷新该选项卡:

$(document).on("submit", "#plaatsen_stap3", function(event) {
/* stop form from submitting normally */    

event.preventDefault();      
    $.ajax({
      type:"GET",
      url:"../plaatsen_advertentie/plaatsen_advertentie_stap3.php",
      cache: false,                 
      data: $("#plaatsen_stap3").serialize(),
      success:function(data){
        $("#tab2").html(data);
      }     
    });
});
但是如果必须付款,我想用付款页面重新加载页面。我想在div重新加载数据之后再这样做,因为我需要在DB中放置一个带有GET数据的payment行。位置是一种选择吗?如果我现在使用它,那么只有div(tab2)加载了付款页面

因此: 1.推送提交 2.通过Ajax提交表单并加载div中的页面/脚本 3.如果需要付款,请签入php脚本(在div中)
4.如果是,请在数据库中添加带有付款数据的行,并使用付款页面重新加载整个页面(url中有一些Get数据(最后插入的id)

因为一旦生成HTML,您就想这样做,请给大约5秒钟的时间

success:function(data){
    $("#tab2").html(data);
    setTimeout(function(){location.href = "/yourpage.php";}, 5000);
}
这将适用于您的用例。这不能从服务器端完成。

我认为load()是您需要的

下面的代码是作为一个指南,我甚至不确定它是否工作(我还没有测试过),但我希望它能有所帮助

我会这样做:

//Step 1
$(document).on("submit", "#plaatsen_stap3", function(event) {
/* stop form from submitting normally */    

event.preventDefault();      
    $.ajax({
      type:"GET",
      url:"../plaatsen_advertentie/plaatsen_advertentie_stap3.php",
      cache: false,                 
      data: $("#plaatsen_stap3").serialize(),
      success:function(data){


   //Step 2 - submit the form and load page/script in div by Ajax 
   //Make sure array[] is an actual array that is sent to the test.php-script.
   $("#tab2").load("test.php", { 'array[]' , function() {
            //Step 3 - check in php script (within the div) if payment is needed (Do this from test.php - don't check the actual div but check values from array[])
            //Step 4 -  if yes,add row with payment data in database and reload entire page with payment page (with some Get data in the url (last inserted id)                     
            //Do this from test.php and use header-redirect to reload entire page   
           $("tab2").html(data); //Do this when test.php is loaded
       }

       } );


      }     
    });
});

所以你想把整个页面刷新到支付页面?你能重新回答一下你的问题吗,你到底想做什么?pendo,是的,这就是我想要的!我想在ajax重新加载后在php脚本中完成,所以这不是唯一的工作…你试过那段代码吗?如果没有,先试试。在这种情况下,你不能使用php重新加载/重定向因为plaatsen_adventie_stap3.php是异步执行的。而且,在用户看到页面之前,您的初始页面的php脚本已经完全执行了,因此在此之后不可能调用任何函数。嗯。我不明白。这是在ajax函数之后完成的?您可以使用JSON将数据发送到yourpage.php。请参阅我在问题中增加了额外的规则。这似乎是个坏主意。依靠秒数来实现这一点?是的,我同意……但想不出比这更好的办法了。
//Step 1
$(document).on("submit", "#plaatsen_stap3", function(event) {
/* stop form from submitting normally */    

event.preventDefault();      
    $.ajax({
      type:"GET",
      url:"../plaatsen_advertentie/plaatsen_advertentie_stap3.php",
      cache: false,                 
      data: $("#plaatsen_stap3").serialize(),
      success:function(data){


   //Step 2 - submit the form and load page/script in div by Ajax 
   //Make sure array[] is an actual array that is sent to the test.php-script.
   $("#tab2").load("test.php", { 'array[]' , function() {
            //Step 3 - check in php script (within the div) if payment is needed (Do this from test.php - don't check the actual div but check values from array[])
            //Step 4 -  if yes,add row with payment data in database and reload entire page with payment page (with some Get data in the url (last inserted id)                     
            //Do this from test.php and use header-redirect to reload entire page   
           $("tab2").html(data); //Do this when test.php is loaded
       }

       } );


      }     
    });
});