I'm trying to do a pretty simple request to another server. I see the expected response in inspection panel of chrome but the browser doesn't allow the request:
XMLHttpRequest cannot load http://search.maven.org/solrsearch/select?q=g%3A%22org.testng%22%20AND%20a%3A%22testng%22&rows=20&wt=json . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
My file is just:
<!DOCTYPE html>
<html>
<body>
<div id="testng-version"></div>
<script type="text/javascript">
//<![CDATA[
var xhr = new XMLHttpRequest();
var url = "http://search.maven.org/solrsearch/select?q=g%3A%22org.testng%22%20AND%20a%3A%22testng%22&rows=20&wt=json";
xhr.open("GET", url, true);
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var resp = JSON.parse(this.responseText);
document.getElementById("testng-version").innerHTML = resp.docs[0].latestVersion;
}
};
xhr.send();
//]]>
</script>
</body>
</html>
Browsing the web or similar questions on StackOverflow didn't help.
You need to setup (and learn about) CORS .
To expand a bit, the site you're attempting to access must send CORS headers. Since that's out of your control, what you can do is proxy the site on your web server.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.