This article mainly introduces three common methods for js cross-origin request data. For more information, see the impact of the same-origin JavaScript policy, or the url under different ports for the same domain name will become an unsupported cross-origin request.
How can we solve this problem at this time? I have made some PREPARATIONS FOR THE cainiao bald head:
1. JavaScript
In the case of native js (without jQuery and ajax support), the client code is usually like this (I suppose it is the http: // localhost: 8080/webs/I .mediapower.mobi/wutao/index.html ):
《script》 var xhr = new XMLHttpRequest(); xhr.open("get", "http://i2.mediapower.mobi/adpower/vm/Bora/js/test.js?1.1.23", true); xhr.onreadystatechange = function() { if (xhr.readyState == 4 && xhr.status == 200) { console.log(xhr.responseText); } }; xhr.send(null);《script》
Save, open http: // localhost: 8080/webs/I .mediapower.mobi/wutao/index.html in the browser, and open the leleconsole:
The browser returns a same-source restriction error, which means that you cannot request url data across domains.
Then, I will first adopt the first policy to use the script tag in html to insert the js script:
(1) Use the script tag to reference and write the src url you need,For example:
Script var callbackfunction = function (data) {console. log ('data from my cross-origin requests --> '+ data. name) ;}; script