0

I am trying to add dummy markers of german companies in Leaflet map using separate geoJSON file, but each time Mozilla returns a non well formed error.

I have tried the solutions proposed in this topic concerning MIME error: "not well-formed" error in Firefox when loading JSON file with XMLHttpRequest

https://forum.jquery.com/topic/firefox-error-on-valid-local-json-load-not-well-formed

But nothing changed. There are a lot of topic about server problems but I'm still in local. I didn't found other people using leaflet and geojson with this problem.

I also tried with a HTML link:

  <link rel="points" type= "application/json" href="assets/js/mess/german_company.geojson">

And use this link in my js file:

//dummy data markers
$.getJSON($('link[rel="points"]').attr("href"), function(data){
  var markers = L.geoJson(data, {
    onEachFeature: function (feature, layer){
      layer.addEventListener("click", function(){
      var result = document.getElementById("result");
      result.innerHTML = feature.properties.Company + "<br/>Sales: " + feature.properties.Sales + " €<br/>Margin: " + feature.properties.Margin + " €";
      });
    }}).addTo(map);

With this method, the map is displayed with the markers, so it works, but I've still this "not well formed" error and I think this causes error with other plugin I use (leaflet.markercluster works but the markers still appear when I zoom out, markers cannot be hide with leaflet removeLayer function)

Anyone have an idea to solve this "not well formed" error? Thanks!

3
  • You can try to amend the mimetype using beforeSend as in this example. It will mean you switching to using ajax instead of getJson, but this solution works because I've used it myself.
    – Andy
    Mar 11, 2015 at 10:26
  • Can you provide a link to the actual data? It's likely that it's invalid JSON.
    – tmcw
    Mar 11, 2015 at 21:50
  • Thanks Andy, it works. I had already switch to ajax call but I only put dataType: 'json' With beforeSend I have no errors Mar 12, 2015 at 11:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.