Two solutions to cross origin read blocking (CORB) blocked cross origin response error reporting of Baidu Web Service API
1. JQuery mode
$(function () {
//Note that at the end add &callback = callback
var url = "http://api.map.baidu.com/place/v2/search?query=ATM机&tag=银行®ion=北京&output=json&ak=F552bedbee2ec8fa6bae7b7a08201&callback=callback";
$.ajax({
type: "get",
async: false,
url: url,
dataType: "jsonp",
jsonp: "callback", //Callback function name (right) of the parameter name (left), default callback, the server side through which to get back to the name of the callback function
jsonpCallback: "callback", //default jquery auto-generated, the name of the callback function returned callback
success: function (data) {
var json = JSON.stringify(data);
console.log(json);
},
error: function (err) {
console.log(err);
}
});
});
2. Client mode
// Provide url address for jsonp service;
var url = "http://api.map.baidu.com/place/v2/search?query=ATM机&tag=bank®ion=Beijing&output=json&ak= F552bedbee2ec8fa6bae7b7a08201&callback=callback";
// Create script tag and set its properties;
var script = document.createElement("script");
script.setAttribute("src", url);
document.getElementsByTagName("head")[0].appendChild(script);
// The callback function after getting the query result;
var callback = function (data) {
var json = JSON.stringify(data);
console.log(json);
};
Done!