1. <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    2. <script>
    3. // 1. new一个promise对象
    4. var promiseObj = new Promise(function(resolve, reject) {
    5. $.ajax({
    6. url: 'http://huruqing.cn:3000/api/film/getList',
    7. data: {},
    8. type: 'get',
    9. success: function(res) {
    10. resolve(res);
    11. },
    12. error: function(err) {
    13. reject(err);
    14. }
    15. })
    16. })
    17. // 2. 获取数据
    18. promiseObj.then(function(res) {
    19. console.log(res);
    20. }).catch(function(err) {
    21. console.log(err);
    22. })
    23. </script>