Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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>
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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

share|improve this answer
    
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 '12 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 '12 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 '12 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 '12 at 16:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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