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

JavaScript cross-domain issues

零到壹度
Release: 2018-04-11 16:09:15
Original
1360 people have browsed it

The content shared with you in this article is the cross-domain issue of JavaScript, which has certain reference value. Friends in need can refer to it

1jsonp

General interfaces use jsonp cross-domain , use jquery's ajax to specify the dataType as jsonp

$.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);
                }
            });
Copy after login

The principle of jsonp supporting cross-domain requests: The principle of JSONP implementing cross-domain requests is simply to dynamically create the

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template