douhanxujiuji6098 2013-01-30 00:56
浏览 48
已采纳

使用ajax提交表单并发布到页面

A bit of a tricky one here Is there a way i can join the two scripts below into one so when the form is posted it actually loads both the different named url's into the 2 different named divs

    <script type="text/javascript">
$(document).ready(function(){
$("#profile").validate({
     debug: false,
    submitHandler: function(form) {$.post('brides_Includes/edit-profile-top.php', $("#profile").serialize(), function(data) {
       $('#results').html(data);
        //This executes the JavaScript passed back by the ajax.
        $("#results").find("script").each(function(i) {
          eval($(this).text());
        });

        $("form#profile")[0].reset();
      });
    }
  });
});
</script>

<script type="text/javascript">
$(document).ready(function(){
$("#profile").validate({
     debug: false,
    submitHandler: function(form) {$.post('brides_Includes/welcome-menu.php', $("#profile").serialize(), function(data) {
       $('#mymenu').html(data);
        //This executes the JavaScript passed back by the ajax.
        $("#mymenu").find("script").each(function(i) {
          eval($(this).text());
        });

        $("form#profile")[0].reset();
      });
    }
  });
});
</script>

I am not sure if this is even possible but would be great if it was :) Many thanks

  • 写回答

2条回答 默认 最新

  • doujingke4981 2013-01-30 01:04
    关注

    Just put the contents of the second submitHandler into the first one:

    submitHandler: function(form) {
       var jqxhr1 = $.post('brides_Includes/edit-profile-top.php', $("#prof...
       function(data) {
           $('#results').html(data);
            //This executes the JavaScript passed back by the ajax.
            $("#results").find("script").each(function(i) {
              eval($(this).text());
            });
          });
        }
      var jqxhr2 = $.post('brides_Includes/welcome-menu.php', $("#pro...
      function(data) {
       $('#mymenu').html(data);
        //This executes the JavaScript passed back by the ajax.
        $("#mymenu").find("script").each(function(i) {
          eval($(this).text());
        });
    
      $.when(jqxhr1, jqhxr2).done(function() { $("#profile")[0].reset(); });
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计