1

I am trying to show attribute information of features in a popup from my postGIS db tables via Geoserver WMS. I have successfully been able to add these layers to the map. However, when I try to grab the attribute information for the same layers via Ajax, console prints an error message stating Uncaught SyntaxError: Unexpected token < On the other hand, the status for URL is 200 i.e. ok as can be seen here:

Screenshot of developer tools' Network tab with status code 200

Still, the preview of this query is

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE ServiceExceptionReport SYSTEM "http://localhost:8888/geoserver/schemas/wms/1.1.1/WMS_exception_1_1_1.dtd">
<ServiceExceptionReport version="1.1.1" >
    <ServiceException code="LayerNotDefined" locator="layers">
        Could not find layer workspace:
    </ServiceException>
</ServiceExceptionReport>

Below are my query string parameters

1.  Query String Parameters (17)
2.  SERVICE:  WMS
3.  version: 1.1.0
4.  request:  GetFeatureInfo
5.  layers: workspace%3AlayerA,workspace%3AlayerB,workspace%3AlayerC,workspace%3AlayerD,workspace%3AlayerE,workspace%3AlayerF,workspace%3AlayerE,
6.  styles: 
7.  bbox: 74.22517776489258,31.487235582017444,74.4019889831543,31.559668260234595
8.  feature_count:  1
9.  width:  1030
10. height:  495
11. format:  image/png
12. srs:  EPSG:4326
13. (empty)
14. x:  247
15. y:  30
16. info_format:  text/javascript
17. callback:  jQuery20309529768737157973_1547708903539_:1547708903542

Everything seems to be working fine here except that it is unable to find the specified layers. I have cross checked in my geoserver’s web.xml file that jsonp is enabled as can be seen below

Screenshot of geoserver's web.xml

I just can’t understand what possibly could go wrong here when I’m successfully calling the same layers in a different function with the same URL and here it doesn’t work.

For further reefrence I’m pasting the code snippet here:

URL='http://localhost:8888/geoserver/wasa_assert/wms?SERVICE=WMS
&version=1.1.0
&request=GetFeatureInfo
&layers=workspace%3AlayerA,workspace%3AlayerB,workspace%3AlayerC,workspace%3AlayerD,workspace%3AlayerE,workspace%3AlayerF,workspace%3AlayerE,
&styles=
&bbox=' + BBOX + '
&feature_count=1
&width=' + WIDTH + '
&height=' + HEIGHT + '
&format=image%2Fpng
&srs=EPSG%3A4326&
&x=' + X + '
&y=' + Y + '
&info_format=text/javascript';

$.ajax({
    url: URL,
    crossDomain: true,
    dataType: "jsonp",
    success: parseResponse
});
  • "Syntax error" means that you have a typo somewhere. In the console you can see, where the syntax error occurs. The file and line number are noted on the right side of the console. Click on it and the console will directly lead you to the file and line. – Stefan Jan 17 at 8:52
  • @Stefan This is exactly the issue, when I click on it, it takes me to <?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE ServiceExceptionReport SYSTEM "http://localhost:8888/geoserver/schemas/wms/1.1.1/WMS_exception_1_1_1.dtd"> <ServiceExceptionReport version="1.1.1" > <ServiceException code="LayerNotDefined" locator="layers"> Could not find layer wasa_assert: </ServiceException></ServiceExceptionReport> I have pasted the code snippet above and seemingly there seems to be no error in it. – DigitalPatwari Jan 17 at 9:44
  • Could it be that there is one comma too much at the end here? &layers=wasa_assert%3Atbl_water_supply_network,wasa_assert%3Atbl_tubewells,wasa_assert%3Atbl_ohr,wasa_assert%3Atbl_filtration_plant,wasa_assert%3Atbl_sewer_lines,wasa_assert%3Atbl_lift_station,wasa_assert%3Atbl_disposal_station, – Stefan Jan 17 at 10:15
  • And as you can see in the syntax highlighting in your question, the string cannot be formed like this. Try this jsfiddle.net/newluck77/tz7xefas and if it solves your issue, let me post it as an answer, please. 😉 – Stefan Jan 17 at 10:40
  • I tried it didn't solve the issue. – DigitalPatwari Jan 17 at 11:01
3

The problem is in the url string. It had two problems:

  1. Additional comma at the end of layers parameter as suggest by @Stefan in comments &layers=workspace%3AlayerA,workspace%3AlayerB,workspace%3AlayerC,workspace%3AlayerD,workspace%3AlayerE,workspace%3AlayerF,workspace%3AlayerE,
  2. Main problem was the missing query_layers parameter as it is a must required parameter for GetFeatureInfo as can be seen below enter image description here

Additional details can be found here. I'm pasting the final working url string below

URL='http://localhost:8888/geoserver/wasa_assert/wms?SERVICE=WMS
&version=1.1.0
&request=GetFeatureInfo
&layers=workspace%3AlayerA,workspace%3AlayerB,workspace%3AlayerC,workspace%3AlayerD,workspace%3AlayerE,workspace%3AlayerF,workspace%3AlayerE
&query_layers=workspace%3AlayerA,workspace%3AlayerB,workspace%3AlayerC,workspace%3AlayerD,workspace%3AlayerE,workspace%3AlayerF,workspace%3AlayerE
&styles=
&bbox=' + BBOX + '
&feature_count=1
&width=' + WIDTH + '
&height=' + HEIGHT + '
&format=image%2Fpng
&srs=EPSG%3A4326&
&x=' + X + '
&y=' + Y + '
&info_format=text/javascript';

$.ajax({
    url: URL,
    crossDomain: true,
    dataType: "jsonp",
    success: parseResponse
});
-1

Try this code below at once :

dataType: 'json',
  • 5
    Could you explain why? – BERA Apr 12 at 9:20
  • This is like a link-only answer, but it doesn't even have a link. If you review some of the top-voted answers, you'll see what we're looking for here. Having only two half sentence lines, this answer is vulnerable to being deleted for being "low quality". – Vince Apr 12 at 12:53

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.