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!
Similar Posts:
- Solution to cross origin read blocking (CORB) blocked cross origin response error
- Ajax “SyntaxError: missing ; before statement” [How to Solve]
- [Solved] Vue Axios error: TypeError: Cannot set property ‘tableData‘ of undefined
- Uncaught Error: _registerComponent(…): Target container is not a DOM element
- JQuery Ajax crossdomain cannot be used in IE [How to Solve]
- Convert to IE9 below $. Ajax to return “no transport” across domains
- After the JVM is started, setting the system property file.encoding again cannot affect the default encoding of the system & sun.jnu.encoding
- Provisional headers are shown
- A parser-blocking, cross site (i.e. different eTLD+1) script, is invoked via document.write