when方法说明

关键字: when  同步  promise
<!DOCTYPE html>
<html>
<head>
<meta charset=”UTF-8″>
<title>Insert title here</title>
<script type=”text/javascript” src=”http://s.thsi.cn/js/m/common/zepto.js“></script>
<script type=”text/javascript”>
    var func1 = function(){
        var xmr = $.ajax({
               type: “POST”,
               url: “func1.php”,
               success: function(msg){
                   console.log(‘successfunc1’);
               }
            });
        console.log(‘func1’);
        return xmr;
    }
    var func2 = function(){
     var xmr = $.ajax({
               type: “POST”,
               url: “func2.php”,
               success: function(msg){
                   console.log(‘successfunc2’);
               }
        });
        console.log(‘func2’);
    return xmr;
    }
    var func3 = function(){
        var xmr =  $.ajax({
               type: “POST”,
               url: “func3.php”,
               success: function(msg){
                   console.log(‘successfunc3’);
               }
        });
        console.log(‘func3’);
        return xmr;
    }
     $.when(func1(),func2()).then(func3).then(func1).done(func2,func3,func1);
</script>
</head>
<body>
</body>
</html>

Leave a Reply

电子邮件地址不会被公开。 必填项已用*标注