Reputation: 95
When sending a GET request to a server why is www.codecademy.com working as the url but not other url's such as www.google.com?
I have a button on my page that when I press sends a get request. The code below works, but why can't I just substitute it for any other url and get some data back? Just want to work on sending GET requests and parsing the data.
$(document).ready(function(){
$("button").click(function(){
$.get("http://www.codecademy.com/",function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
});
});
Upvotes: 0
Views: 1449
Reputation: 38529
Check the error returned:
XMLHttpRequest cannot load http://www.google.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '' is therefore not allowed access
In a nutshell, this is to do with CORS
This SO post may help
Origin is not allowed by Access-Control-Allow-Origin
... by 'help' - I mean help to understand, not help to GET request google from client side Javascript.
You could of course charm the 'Security Princess' of google into opening it up for you, but I highly doubt that's an option ;-)
Upvotes: 4