Cannot parse the spec file: A JSONObject text must begin with '{'

627 Views Asked by At

I know this question has been asked before but i have an implementation specific doubt so i am posting it here. I am printing the map created using Geoserver with the help of the mapfish plugin and i am getting parse error in the ajax request that i am making. Here is the code snippet responsible for printing the map and the error :

var spec = {
    "mapTitle":"MyMap",//"DistrictMap",
    "units":"degrees",
    "srs":"EPSG:4326",
    "layout":"A4 portrait",//"A4 Landscape",
    "dpi":300,//300,
    "layers": [
    {
        "type": 'WMS',
        "layers": layers_param,
        "baseURL": 'http://localhost:8081/geoserver/wms',
        "format": 'image/jpeg'
     }
    ],
   "pages": [
   {       
        "center": [6, 45.5],
        "scale": 4000000,
        "dpi": 150,
        "geodetic": false,
        "rotation":0,
        "mapTitle":"A custom title",
        "comment":"A custom comment",
        "mapComments":"kkomment"
      }
    ]
};

  var spec_str = JSON.stringify(spec);

  $.ajax({
    type: "POST",
    url: 'http://localhost:8081/geoserver/pdf/create.json',
    dataType:'json',
    data:spec_str,        
    success : function(){
      alert('Hello');
    }

  });

It throws the following error in the console:

Error while generating PDF:
java.lang.RuntimeException: Cannot parse the spec file: A JSONObject text 
must begin with '{' at character 0: 
at org.mapfish.print.MapPrinter.parseSpec(MapPrinter.java:190)
at.........and some more lines of crap!

Update: When i added "contentType" : "application/json" to the request..i got another error stating : INVALID CORS REQUEST

0

There are 0 best solutions below