2

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 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>

1 Answer 1

1

It sounds like you're violating the same origin policy: http://www.w3.org/Security/wiki/Same_Origin_Policy

Openlayers describes it and shows how to get around it: http://docs.openlayers.org/library/request.html, http://trac.osgeo.org/openlayers/wiki/FrequentlyAskedQuestions#ProxyHost

4
  • i am not using CGI so openlayers proxyhost will not help. Also I am trying to use JSON-P of ExtJS but not sure what to add to the callback
    – Sam007
    Aug 17, 2012 at 18:39
  • @Sam007 the callback is the function that gets called after the data is loaded. The json data gets passed into the callback function as the first parameter. You should put code into the callback function that does something with the returned data: maybe you add it to a datastore, maybe you just add it to the map as a popup.
    – canisrufus
    Aug 17, 2012 at 19:20
  • sorry i forgot to add the script, updated my question. So what i wanted to know, was wat should i add in this callback
    – Sam007
    Aug 17, 2012 at 20:09
  • Still stuck here @canisrufus. If you goto 128.196.142.94/cgi-bin/proxy.cgi , you can see that it redirects me to the OpenLayers website but the issue continues to persist
    – Sam007
    Aug 21, 2012 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.