双接口(回调)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>
上一篇:php在没用xdebug等调试工具的情况下如何让调试内容优雅地展现出来?--php数组格式化


下一篇:Aws api gateway Domain name