Use with IO

Source
Output
QRCode
<!doctype html> <html> <head> <meta charset="utf-8"/> <title>promise-use with io module</title> <link rel="stylesheet" type="text/css" href="assets/bootstrap.css"> <script src="//g.alicdn.com/kissy/k/5.0.1/seed.js"></script> </head> <body> <h4>和 io 一起使用</h4> <p>查看代码,点击下面按钮观察结果</p> <button id="demo2" class="btn btn-default btn-sm">点我执行</button> <script type="text/javascript"> require(['node', 'promise', 'io'], function(Node, Promise, IO){ var $ = Node.all; $('#demo2').on('click', function(){ var defer = new Promise.Defer(), promise = defer.promise; promise.then(function(success){ alert(success); },function(reason){ alert(reason); }); new IO({ url : 'test.php', //这是一个不存在的请求,在这里只是为了做个演示 type : 'get', data : { test : 'just a test' }, success : function(impossibleInThisCase){ alert(impossibleInThisCase); }, error : function(errorHere){ //由于在这个demo中 url 是不存在的,故一定会进到这里 defer.reject('I will jump into fail callback because of a error url'); } }) }); }) </script> </body> </html>