I am using OpenLayers 2.1.3 and using OpenLayers I obtain the GetFeatureInfo result but it is a web page, I want to get the output fields into a variable so I can display them in grid.


Can you update your version of Geoserver? Newer (2.4+) versions of Geoserver support JSON Natively for the response from the getFeatureInfo operation.

If you can't update you have two options:

  1. Request for the output in GML and then parse the result in your Client code.

  2. Otherwise, you can use this 'hack' to get the response in JSON.

Once you have the results in your client code, you can then create an array and add the values to it.

  • there is other problem too, when i call var request = OpenLayers.Request.GET({ url: url, callback: handler }); there is an error "XMLHttpRequest cannot load (url) No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://(IP address)' is therefore not allowed access.What i need to do i googled it and found cross domain error, but when i put url in browser it works fine.What is that I am missing?and i tried your hack but the result is same as plain/html.(why so)? – Ahmed Feb 13 '14 at 9:07
  • @user3301246 That error is because of the Geoserver being on a differnt domain than your Application. You need a Proxy for this. Just look at these search results – Devdatta Tengshe Feb 13 '14 at 9:50
  • I have resolved it now i m not getting above XMLRequest Acess-Allow_Origin error but what i get from response.text is the text of proxy php file, I want to get the data of url which comes from getfeature info request.Thanks for your help – Ahmed Feb 14 '14 at 6:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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