Home > Web Front-end > JS Tutorial > body text

What are 3 cross-origin requests explained for asynchronous execution

一个新手
Release: 2017-09-26 09:33:53
Original
1286 people have browsed it

<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="UTF-8" />
  <title>Document</title>
 </head>
 <body>
  <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  <script type="text/javascript">
         console.dir(Promise);

         // 输出构造函数 何为构造函数  白话解释 就是带有属性的函数就是构造函数  首字母大写(规范)
         //

            // 以下为3个异步  同时执行  所以下面的data1都是undefined;

                let data1;
                 $.ajax({
                    type:"post",
                    url:"http://jspang.com/DemoApi/typeGoods.php",
                    dataType:"json", //返回格式
                    success: function (data) {
                     console.log(data[0][0].price); // 18
                     data1=data[0][0].price;
                    },
                    error: function () {
                        console.log("亲,出错了");
                    }
                });
                 $.ajax({
                    type:"get",
                    url:"https://gsp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?cb=callback&wd="+data1+"&sc=hao123&_=1506355261424",
                    dataType:"jsonp", //返回格式
                      jsonp: "cd",
                     jsonpCallback:"callback",
                    success: function (data) {
                         console.log(data);  // Object {q: "18", p: false, s: Array[10]}

                    },
                    error: function () {
                        console.log("亲,出错了1");
                    }
                });
                 $.ajax({
                    type:"get",
                    url:"https://gsp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?cb=callback1&wd="+data1+"&sc=hao123&_=1506355261424",
                    dataType:"jsonp", //返回格式
                      jsonp: "cd",
                     jsonpCallback:"callback1",
                    success: function (data) {
                         console.log(data); //Object {q: "false", p: false, s: Array[10]}
                         // 到此结束   没有需求 就不用resolve了
                        // resolve(data[0][0].price);
                    },
                    error: function () {
                        console.log("亲,出错了0");
                    }
                });
    </script>
 </body>
</html>
Copy after login

The above is the detailed content of What are 3 cross-origin requests explained for asynchronous execution. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!