Posts: 13
Joined: Tue Aug 15, 2023 7:10 am


Fri Sep 08, 2023 4:18 am

I was using this method Highcharts.getJSON(a, b) to get my maps. I was putting a path to the file with geojson data in a.
Now, I want to use geojson data from the server, I tried putting it into a but it just doesn' work.
How am I supposed to do this?

Posts: 972
Joined: Fri Dec 16, 2022 11:45 am

Re: Highcharts.getJSON

Fri Sep 08, 2023 8:47 am


Thanks for the question!

If you take a look at the getJSON function:

Code: Select all

    function getJSON(url, success) {
                url: url,
                success: success,
                dataType: 'json',
                headers: {
                    // Override the Content-Type to avoid preflight problems with CORS
                    // in the Highcharts demos
                    'Content-Type': 'text/plain'

you'll see that it's just sending a basic request to the server and hope to receive a JSON in return, and pass it to the success callback function.

To be honest, I don't see anything that could be wrong with this function as it's pretty basic.

Are you sure that your server returns a proper JSON string? Are you sure that there's no problem with CORS or security headers?

If this function does not work for you, you can try out axios or any other library that simplifies sending HTTP requests and create a fully custom request function with your setup (it should be only a few lines of code so not a lot of complexity).

Please let me know if you have any more questions.

Best regards!
Highcharts Developer

Return to “Highcharts Maps”