[OpenLayers-Users] Catching JSON

Stephen Woodbridge woodbri at swoodbridge.com
Fri Aug 17 11:45:09 PDT 2012


Is you main page loading from http://128.196.142.94:9000/...
If not you are trying to make an Ajax request to a host that is not the 
same as the page that you loaded. This is not allowed because of Same 
Origin Policy. You can setup a proxy to work around this.

-Steve W

On 8/17/2012 2:35 PM, Smaran Harihar wrote:
> Hi,
>
> I am returning a JSON to a GeoExt app and this is the code that is
> collecting the return,
>
>      var control = new OpenLayers.Control.Click({
>                            trigger: function(evt) {
>                            var lonLat = evt.xy;
>                            if (popup) popup.close();
>                            var  request = Ext.Ajax.request({
>       url:"http://128.196.142.94:9000/info?lat="+
> panel.map.getLonLatFromViewPortPx(lonLat).lat +"&lon=" +
> panel.map.getLonLatFromViewPortPx(lonLat).lon,
>                            disableCaching: false,
>                            success: function(response) {
>       var obj = Ext.decode(response.responseText);
>       console.log(obj);
>       console.dir(obj);
>       addToPopup(lonLat, response.responseText);
>       },
>   failure: function(response) {
>       console.log('server-side failure with status code ' +
> response.status);
>       addToPopup(lonLat, "Server side Failure");
>   }
>                                   //callback: myhandler
>                       });
>      }});
>
> I wish to obtain the returned JSON and then assign it to the popUp but
> whenever I try to connect to the App it is returning the following error,
>
>      OPTIONS
> http://128.196.142.94:9000/info?lat=55.44873046875&lon=-118.17626953125
> 405 (Method Not Allowed)
>      XMLHttpRequest cannot load
> http://128.196.142.94:9000/info?lat=55.44873046875&lon=-118.17626953125.
> Origin null is not allowed by Access-Control-Allow-Origin.
>      test.html:222server-side failure with status code 0
>
> If you simply pass the url
> `http://128.196.142.94:9000/info?lat=55.44873046875&lon=-118.17626953125` <http://128.196.142.94:9000/info?lat=55.44873046875&lon=-118.17626953125%60>
> you will obtain the JSON but for some reason there is failure that keeps
> occurring in the application.
>
> Is there CORS that can be used in the OpenLayers or GeoExt. I have tried
> using ExtJS JSON-P but I am not sure what should I enter in the
> 'callback' of,
>
> <script src="http://domainB.com/users?callback=someCallback"></script>
>
>
> --
> Thanks & Regards
> Smaran Harihar
>
>
>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>



More information about the Users mailing list