Frage

I am trying to make a request to the yahoo wheather forcast like this

function parseXml(woeid)
{
 $.ajax({
  type: "GET",
  url: "http://weather.yahooapis.com/forecastrss?w="+woeid,
  dataType: "xml",
  success: parse_wheather
 }); 
} 

and I get the following error message

XMLHttpRequest cannot load http://weather.yahooapis.com/forecastrss?w=1937103. Origin http://XXXXXXXX.com is not allowed by Access-Control-Allow-Origin.

I know that I can't make the request from localhost , but I am not running a localhost How can I solve this problem ??

War es hilfreich?

Lösung

I know that I can't make the request from localhost

Actually, due to the same origin policy restriction you cannot send cross domain AJAX calls. So you are not only limited to localhost. You are limited to anything different than http://weather.yahooapis.com. So unless the page containing your javascript is hosted on this domain you cannot send AJAX requests to it.

Here's a guide you might take a look at about cross domain AJAX calls. In your case you could use a server side bridge. So you will define a server side script on your domain that will fetch the remote domain results and then you could send the AJAX request to your script in order to avoid violating the same origin policy restriction.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top