ajax and promise
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