Quick actions

cmd+k|ctrl+k

Navigation

Languages

ajax and  promise

Snippet info

Language

JavaScript

Visibility

public

Author

pheker

Created

2018-02-02T09:39:31Z

Updated

2018-02-03T09:33:31Z

console.log("Hello World!");
var $ = require('./dio.js');
var Promise = require('./tria.js');
console.log($,Promise)



var async = function(flag){
            var count = Math.round(Math.random()*8+1);//1-9
            return new Promise(function(resolve,reject){
                //模拟异步成功或失败
                if(count%2 == 0){
                    resolve("成功:"+flag+":"+count);
                }else{
                    reject("失败:"+flag+":"+count)
                }
            });
        }

        async("#1").then(function(value){
            console.log("then1:",value);
            return async("#2");
        }).catch(function(value){
            console.log("catch1:",value)
        }).then(function (value) {
            console.log("then2:",value)
        },function(value){
            console.log("catch2:",value)
        })
INFO