企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
## 1. ajax本身就是一个promise > 在html页面引入不能用import,所以不需要export,可直接用script导入,即可调用 - http.js ``` class HTTP { request({url,type="get",dataType}){ return $.ajax({ url, type, dataType, }) } } class MovieModel extends HTTP{ getTop250(){ return this.request({ url:"https://douban.uieee.com/v2/movie/top250", dataType:"jsonp" }) } } ``` - html ``` <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script> <script src="http.js"></script> <script> var http = new HTTP() http.request({ url:"https://douban.uieee.com/v2/movie/top250", dataType:"jsonp", }).then(res=>{ console.log(res) }) </script> ``` ``` var movie = new MovieModel() movie.getTop250().then(res=>{ console.log(res) }) ```