Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7801871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:04:51+00:00 2026-06-02T01:04:51+00:00

Pulling my hair out here. Jquery, Multiple JSON files & Ajax I have a

  • 0

Pulling my hair out here.

Jquery, Multiple JSON files & Ajax

I have a python script that is gathering data and dumping JSON files into a folder on my webserver

I am trying to visualise that data.

Basically I am first drawing an SVG map and coloring it in with a dummy json file. Subsequently I want to color it in using the JSON data. Each JSON file will represent one complete rendering (coloring) of the map.

I am using an Ajax call to a php script that returns the files in the directory. I then want to use Ajax (or the shorthand .getJson) to lad the data in that file -colour the map, and then move on to the next one (end result is an animation). The problem is the asynchronous nature of AJAX and not having any control over the timely execution and completion of the Ajax bit. Obviously i don’t want to make a synchronous call because i don’t want to lock up the browser.

Here’s my code (apologies -it’s fairly hefty)

jQuery(document).ready(function() {

$(function() {

    var map, c = [];
    var dep_data;
    var val = {};
    var max= 0;
    var vals = new Array();

    c = $('#map');
    c.height(c.width()*.5);

    drawMap('mapData.json');

    function drawMap(url){
        console.log(url);
        $.ajax({
        url: 'mapData.json',
        dataType: 'json',
        success: function(data) {

            dep_data = data;

            map = window.m = $K.map('#map', 600, 800);
            map.loadMap('ireland.svg', function() {
                map.loadStyles('./mapping_files/style.css');
                map.addLayer({
                    id: 'regions',
                    key: 'name-1'
                });

                colourMap(dep_data);

                    var mapData = $.ajax({
                        url: './php/getfiles.php',
                        type : 'POST',
                        dataType: 'json',
                        success: function (files){

                            for (_a in files.response){
                                for (_b in files.response[_a]){
                                      $.ajax({
                                        url: files.response[_a][_b],
                                        dataType: 'json',
                                        success: function (json){
                                          colourMap(json);
                                          $(this).dequeue();
                                        }
                                      });
                                }       

                            }
                        },

                        error: function (files){
                            console.log(files.message);
                        },

                    });

                });

            }
        });



    }

    colourMap = function(data) {

    //do the coloring in...

}

}); });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:04:52+00:00Added an answer on June 2, 2026 at 1:04 am

    Ok,

    You might want to decouple your json processing code from the ajax success() function. Instead, sort the data and store it in a global variable. Once all data has been received (check for that), you can call a function to draw your SVG, thus having control over timing. Its like the $.document(ready) of jquery

    EDIT:

    Depending on your scenario, you need a more efficient queue system for your json files. One method would be to load json files in chunks instead of randomly. You’ve mentioned that a new file is created every 10 minutes, so obtain the first json file and acquire, lets say, 35 more json files, in effect obtaining 6 hours of data. If one folder currently has less than 36 files, you can choose to wait until all 36 are present, then run the svg code and move on to, or wait for, the next 36 json files. This brings in control over timing, where one svg file represents 6hrs of data. You can also change from 36 to any reasonable value

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im ready to start pulling my hair out here. Trying to use jquery ajax
I'm on the verge of pulling my hair out over this. Here I have
I am pulling my hair out. I have created some simple functions that generate
Pulling my hair out here... have been playing around with this for the last
I'm pulling my hair out here, because I just can't seem to get this
Pulling my hair out over this one. I have one wordpress install at /2009
I'm pulling my hair out on this one. I have a site which is
I have been pulling my hair out about this since Friday and I am
Ok so I'm lost here, frustrated and pulling my hair and out. Plus probably
I'm pulling my hair out over here and I'm not sure what's causing it.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.