0

I am trying to get the feature attributes from WMS service published in GeoServer and showing the attributes as a popup in the .NET application.

When I make an Ajax call it gives "requested JSON parse failed" exception, However, the URL works and returns JSON data in a browser.

PFB code block:

 var url = wmsSource.getGetFeatureInfoUrl(
        evt.coordinate, viewResolution, 'EPSG:3857',
        { 'INFO_FORMAT': 'jsonp' }); //text/html

      if (url) {
          var parser = new ol.format.GeoJSON();
          var lookup = {};
          $.ajax({
              url: url,
              dataType: 'jsonp',
              method: 'GET',
              contentType: 'application/json; charset=utf-8',
              success: function (response) {
                              alert("hI");                                  
                          },
              error:  function(jqXHR, exception) {
                          if (jqXHR.status === 0) {
                              alert('Not connect.\n Verify Network.');
                          } else if (jqXHR.status == 404) {
                              alert('Requested page not found. [404]');
                          } else if (jqXHR.status == 500) {
                              alert('Internal Server Error [500].');
                          } else if (exception === 'parsererror') {
                              alert('Requested JSON parse failed.');
                          } else if (exception === 'timeout') {
                              alert('Time out error.');
                          } else if (exception === 'abort') {
                              alert('Ajax request aborted.');
                          } else {
                              alert('Uncaught Error.\n' + jqXHR.responseText);
                          }
                      }
          });

      }

The JSON response on browser from the URL is:

{"type":"FeatureCollection","features":[{"type":"Feature","id":"village_maps.115","geometry":{"type":"MultiPolygon","coordinates":[[[[79.13895583,25.3233091],[79.13482866,25.32499247],[79.13317419,25.32360682],[79.12904055,25.32355175],[79.11112382,25.32624913],[79.11054308,25.32213731],[79.10696928,25.32399947],[79.1034709,25.32324635],[79.09974985,25.31942675],[79.09800786,25.32022119],[79.0979736,25.31867895],[79.09166887,25.31635774],[79.08927284,25.31821429],[79.08661964,25.31754376],[79.07432635,25.32064035],[79.07417549,25.32250699],[79.07728205,25.32362325],[79.08025674,25.32743095],[79.08831236,25.32775063],[79.09032527,25.33283685],[79.08757208,25.33551219],[79.07363746,25.34013379],[79.07406066,25.34194949],[79.07257536,25.34266333],[79.07427301,25.34407714],[79.07571542,25.35252829],[79.08648018,25.35161346],[79.09057063,25.35709824],[79.09046858,25.35497181],[79.08648332,25.34991794],[79.09656147,25.34616603],[79.09976983,25.35526709],[79.10152538,25.3574017],[79.10472238,25.35755957],[79.10617664,25.36085029],[79.11197018,25.35874088],[79.11217002,25.35463277],[79.11563481,25.35019114],[79.11465262,25.348675],[79.11888327,25.34534672],[79.12336584,25.34908317],[79.12612299,25.34570295],[79.13045243,25.34409387],[79.13712699,25.34887448],[79.13983827,25.34651654],[79.13916554,25.34453145],[79.14239623,25.34280575],[79.14273195,25.33875767],[79.1448726,25.33784395],[79.14887941,25.33979993],[79.1535527,25.33947772],[79.15312606,25.33435852],[79.15454125,25.33390489],[79.15492136,25.330539],[79.15069001,25.3216973],[79.14512387,25.32357109],[79.13895583,25.3233091]]]]},"geometry_name":"geom","properties":{"objectid_1":115,"objectid_2":115,"objectid":115,"shape_leng":0.313447905145,"pipeline_l":2.72376,"shape_le_1":0.313447907911,"shape_area":0.00194710986264}}],"totalFeatures":"unknown","numberReturned":1,"timeStamp":"2019-08-21T05:33:08.387Z","crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::3857"}}}

  • At least the coordinates obviously are not in EPSG:3857 but in EPSG:4326. – user30184 Aug 21 at 6:57
  • Thanks for the response. I have changed the Coordinate reference system in my code and in GeoServer Layer as well, But still the error is same :- "Requested JSON parse failed". – user684805 Aug 21 at 7:20
  • This time error same same "Requested JSON parse failed" , However when I run the url created in browser it gave below response :<ServiceException code="InvalidFormat" locator="info_format"> Invalid format 'jsonp', supported formats are [text/plain, application/vnd.ogc.gml, text/xml, application/vnd.ogc.gml/3.1.1, text/xml; subtype=gml/3.1.1, text/html, application/json] </ServiceException> – user684805 Aug 21 at 7:27
  • On using "Application/JSON" , Url response on browser is : {"type":"FeatureCollection","features":[],"totalFeatures":"unknown","numberReturned":0,"timeStamp":"2019-08-21T07:23:42.893Z","crs":null} – user684805 Aug 21 at 7:29
  • I guess that the parsing error is another issue but crs was certainly wrong. – user30184 Aug 21 at 7:34

Your Answer

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

Browse other questions tagged or ask your own question.