双接口(回调)promise cb
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <div style="background: red;" id="camera"></div> <script src="js/jquery-1.11.0.js"></script> <script> var camera = document.getElementById('camera'); var captureVideo = function captureVideo(opts, cb) { opts = opts || {}; return new Promise(function (resolve, reject) { $.ajax({ type:"get", url:"http://www.jspang.com/DemoApi/newsApi.php", async:true, success:function(ret){ resolve(ret); if (typeof cb === 'function') cb(ret, null); }, error:function(err){ reject(err); if (typeof cb === 'function') cb(null); } }); }); }; captureVideo({ width:231, height:123 },(ret,err) => {//第一次回调 console.log(12233) console.log(ret); //console.log(err); } ).then((res)=>{//第二次回调 console.log(5555) console.log(res); }) </script> </body> </html>
作者:freddyhuang
出处:https://www.cnblogs.com/freddyhuang
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。