GeoNames Home | Postal Codes | Download / Webservice | About 

GeoNames Forum
  [Search] Search   [Recent Topics] Recent Topics   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Permission denied to call method XMLHttpRequest.open  XML
Forum Index -> FAQ - frequently asked questions
Author Message
marc



Joined: 08/12/2005 07:39:47
Messages: 4406
Offline

Calling the geonames webservice from javascript gives the Error: uncaught exception: Permission denied to call method XMLHttpRequest.open

Most browsers enforce a cross-domain security restriction. This means your javascript code can only access the server from which the javascript has been loaded. As geonames.org is a different server you cannot directly call the geonames webservice using XMLHttpRequest.

Workarounds :

* use one of our JSON webservices. With JSON you don't have this problem : http://www.geonames.org/export/JSON-webservices.html
* Use a software proxy on your server forwarding the requests to geonames.org.
* use apache modrewrite


Links :

http://nothing-more.blogspot.com/2005/09/xmlhttprequest-security.html
http://spaces.msn.com/members/siteexperts/Blog/cns%211pNcL8JwTfkkjv4gg6LkVCpw%212776.entry


[WWW]
Anonymous



Thanks for your nice system - its great.

I'm using your service with javascript with the url:

request = 'http://ws.geonames.org/findNearbyPostalCodesJSON?lat=' + point.y + '&lng=' + point.x + '&callback=getLocation';

and its working very good.

I found the query http://ws.geonames.org/wikipediaSearch and I got the problem to access it with java-script.

Is there a JSON query too for the wikipedia search like

http://ws.geonames.org/wikipediaSearchJSON?q=cologne&maxRows=10&lang=de

It would be a nice help.

Erik

erik (-at-) koelschwasser (point) de
marc



Joined: 08/12/2005 07:39:47
Messages: 4406
Offline

Hi Erik

All Wikipedia services are now available in XML and JSON.

Marc

[WWW]
Fuzzy Orange



Joined: 20/12/2006 12:48:24
Messages: 5
Offline

Im having a huge problem with this

Im getting a 403 permission denied error but im not using javascript

Am using PHP fopen

Code:
function get_longlat($postcode,$placename) 
 {
         $ret = "";
         $url = "http://ws.geonames.org/postalCodeSearch?postalcode=" . $postcode . "&placename=". $placename ."&maxRows=1";
 		$url = str_replace(" ","%20",$url);
 		
         $handle = fopen($url,"rb");
         $contents = "";
         while (!feof($handle)) { $contents .= fread($handle, 8192); }
         fclose ($handle);
         
 		preg_match('/<lat>([^\<]*)/', $contents, $matches);
         $lat = $matches[1];
         $ret = $ret . $lat . ",";
         preg_match('/<lng>([^\<]*)/', $contents, $matches);
         $lng = $matches[1];
         $ret = $ret . $lng;
         return $ret;
 }


Its only happening on one of my hosting accounts - on the other the code runs fine

Is there some security setting that has to be turned on on the linux server to allow it to make external http requests?
LauraWilson



Joined: 17/04/2007 21:39:35
Messages: 1
Offline

We are using the FindNearestAddress service via javascript and are getting the permission denied error.
Is this service available as JSON? I didn't see it in the list.....

http://ws.geonames.org/findNearestAddress
marc



Joined: 08/12/2005 07:39:47
Messages: 4406
Offline

Hi Laura

Yes it is available as JSON : http://www.geonames.org/maps/reverse-geocoder.html

Cheers

Marc

[WWW]
akhan



Joined: 05/06/2007 22:31:47
Messages: 3
Offline

Hey im a bit confused. I to get the XMLHttp error but I tried doing it by jSON type. I'm using the DOJO framework what exactly do I need to do to run it as a json and use the work around?

My current code is this
Code:
   	function GetCountryData(coory,coorx)
 	{
 		sendUrl = 'http://ws.geonames.org/countrycode?lat=' + coory + 'lng=' + coorx + '&type=JSON';
 	dojo.io.bind({
 			url: sendUrl,
 			load: function(type, data, evt){alert(data)},
 			error: function(type, data, evt){},
 			mimetype: "text/plain" 
 		});
 	}
 	
marc



Joined: 08/12/2005 07:39:47
Messages: 4406
Offline

I don't know the DOJO framework, but it seems it is not making a JSON call. Did you try using another mime type? In this example they are using text/json :

http://today.java.net/pub/a/today/2006/04/27/building-ajax-with-dojo-and-json.html

Marc

[WWW]
johnknyc



Joined: 25/07/2008 02:12:20
Messages: 1
Offline

The problem is the same-origin policy that most browsers enforce.

Here is on solution to the problem.

http://glowfilter.com/articles/web/development/permission-denied-to-call-method-xmlhttprequest.open/

senthil



Joined: 08/08/2008 12:04:08
Messages: 1
Offline

i am working on google map to integrate weather onto the map.I am getting permission denied error when using json for weather.

this is my code

GDownloadUrl("http://ws.geonames.org/findNearByWeatherJSON?lat="+point.y+"&lng="+point.x+"",
function(data2){
var jsonData = eval('(' + data2 + ')');
weatherHTML = "<table width='200'><tr><td align='left'>Temp : </td><td align='left'>"+jsonData.weatherObservation.temperature+"</td></tr><tr><td align='left'>clouds : </td><td align='left'>"+jsonData.weatherObservation.clouds+"</td></tr></table>"
});

Hope someone will help me to make this work.
marc



Joined: 08/12/2005 07:39:47
Messages: 4406
Offline

GDownloadURL is using XmlHttpRequest behind the scenes and subject to the same restrictions.

http://code.google.com/apis/maps/documentation/reference.html#GDownloadUrl

You will have to use a JSON call to read data from the GeoNames server directly with the browser.

Marc

[WWW]
 
Forum Index -> FAQ - frequently asked questions
Go to:   
Powered by JForum 2.1.5 © JForum Team