解决方案 »

  1.   

    <form action="1.php" target="frame">
        <input type="text" name="abc" />
        <input type="submit" value="提交" />
    </form>
    <iframe name="frame" src="" width="0" height="0"></iframe>
    <script type="text/javascript">
        function send(){
            $("form").attr({action:"2.php",target:"_self"}).submit();
        }
    </script>
    1.php<script type="text/javascript">
        alert("you send:<?php echo $_GET['abc'];?> now send other form");
        parent.send();
    </script>
    原理很简单:先提交到iframe,成功后修改表单再提交。
      

  2.   

    参考: Chain ajax and execute it in sequence. Jquery Deferred
    使用类似下面的代码,假设a里面是你第一个想要提交的页面,b里面是你想要提交的第二个页面function a() {
        return $.post(...).then(function(result) {
            if(result)
                return result;//continue on "success" path.
            else
                return $.Deferred().reject('a').promise();//convert success to failure.
        }, function() {
            return 'a';//continue on failure path.
        });
    }
    function b() {
        return $.post(...).then(function(result) {
            if(result)
                return result;//continue on "success" path.
            else
                return $.Deferred().reject('b').promise();//convert success to failure.
        }, function() {
            return 'b';//continue on failure path.
        });
    }a().then(b).then(function() {
        console.log("successful");
    }, function(id) {
        console.log("failed: " + id);
    });官网api: deferred.then()(英文)
    中文看这里: jQuery.Deferred对象var myDeferred = $.post('/echo/json/', {json:JSON.stringify({'error':true})})
        .then(function (response) {
                if (response.error) {
                    return $.Deferred().reject(response);
                }
                return response;
            },function () {
                return $.Deferred().reject({error:true});
            }
        );myDeferred.done(function (response) {
            $("#status").html("Success!");
        }).fail(function (response) {
            $("#status").html("An error occurred");
        });
      

  3.   


    $(function(){
      $.post(
        'url',
        {
          //第一个form中要使用的参数,这里不再通过form去传参数,而是用ajax
        },
        function(data){
          //从后台返回一个boolean来判断是否执行成功
          if(data){
            $.post();//通过ajax发送第二个form中的数据
            //或者$("#form2").submit();提交第二个表单。
          }
        }
      )
    })