SOURCE

console 命令行工具 X clear

                    
>
console
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

    <script type="text/javascript">
    $(function(){
    function getJSONP(url_, callback) { //jsonp由回调函数和数据组成
        var url=url_;
        if (!url) { return; } //如果url为空,则不运行
        //生成随机函数名
        var a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
        //生成随机下标
        r1 = Math.floor(Math.random() * 10);
        r2 = Math.floor(Math.random() * 10);
        r3 = Math.floor(Math.random() * 10);
        var name = 'getJSONP' + a[r1] + a[r2] + a[r3];
        var cbname = 'getJSONP.' + name;
        //判断url地址中是否含有问号,处理url
        if (url.indexOf('?') == -1) {
            url += "?jsonp=" + cbname;
        }else {
            url += "&jsonp" + cbname;
        }
        //定义被脚本执行的回调函数
        getJSONP[name] = function (data) {
            try {
                callback && callback(data);
            }
            catch (e) {}
            finally {
                //删除该函数以及script标签,防止污染
                delete getJSONP[name];
                script.parentNode.removeChild(script);
            }
        }
        //动态创建script标签
        var script = document.createElement('script');
        //定义src
        script.src = url;
        document.getElementsByTagName("head")[0].appendChild(script);
    
 }
    console.log("sdfadfaf");
getJSONP("https://class.imooc.com/api/jsonp", function (data) {
        console.log(data);

    });



        $("#btn").click(function(){
            console.log("dfasdfa");
            $.ajax({
                async : true,
                url : "https://api.douban.com/v2/book/search",
                type : "GET",
                dataType : "jsonp", // 返回的数据类型,设置为JSONP方式
                jsonp : 'callback', //指定一个查询参数名称来覆盖默认的 jsonp 回调参数名 callback
                jsonpCallback: 'handleResponse', //设置回调函数名
                data : {
                    q : "javascript", 
                    count : 1
                }, 
                success: function(response, status, xhr){
                    console.log('状态为:' + status + ',状态是:' + xhr.statusText);
                    console.log(response);
                }
            });
        });
    });
</script>

</head>
<body>

    <div id="mydiv">
        <button id="btn">点击</button>
    </div>
</body>
</html>