0

这里有点棘手有没有一种方法可以将下面的两个脚本合并为一个,所以当表单发布时,它实际上将两个不同的命名 url 加载到 2 个不同的命名 div 中

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

我不确定这是否可能,但如果是的话会很棒:)非常感谢

4

2 回答 2

1

只需将第二个的内容submitHandler放入第一个:

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(); });
}
于 2013-01-30T01:04:33.417 回答
1
<script>
function ajax_loadpage(loadUrl,output_container)
    {
        $.post
        (
            loadUrl,
            {language: "php", version: 5},function(responseText){$(output_container).html(responseText);},"html"
        );
    }

ajax_loadpage("url1.php","#div1");
ajax_loadpage("url2.php","#div2");

</script>

the first parameter should be supplied with the URL you want to load, the second will be the name of the id of the element you want to load it into.

于 2013-01-30T08:46:06.307 回答