How do I load data from a dynamic json file?

0 favourites
  • 12 posts
From the Asset Store
Data+ is the best Data Management solution for Construct 3. It contains 4 Addons (Plugin & Behavior).
  • Hi,

    To test and finetune a lot of properties (different speeds, strengths, powers, ...) in my game I want to be able to change them while playing the game. All the values are in a dictionary, which is loaded from a json-file. I can host the game and the file on the same webserver (to prevent cross-domain problems which I have in preview mode) and change the values in the json-file on this server.

    But when I change the values and reload the json-file in the project, the data imported from the file isn't changed. Even if I reload (ctrl + F5) the gamepage, it still loads the old data that doesn't exist anymore.

    I made a new project with a simplified version of this problem:

    Any ideas to solve this?

    Thanks!

    Wim

    Tagged:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Not particularly familiar with this, but stackoverflow.com/questions/367786/prevent-browser-caching-of-ajax-call-result sounds relevant.

    You may need to include jquery as a javascript library in your project. I'm not familiar enough with javascript or jquery to know if you can do it without the jquery library.

    Although seems to me this should be (to my limited knowledge) a server side setting, on your webserver, to never serve cached files. Or at least for the directory your updated files reside in.

  • This tip of oosyrag about caching seems to get me a step along the way, but I'm not there yet.

    To avoid a cached result, JQuery doesn't seem necessary, adding a unique ID to the URL should be enough if I understand the following correctly. But unfortunately it doesn't work. I still get the same result.

    w3schools.com/js/js_ajax_http_send.asp:

    In the example above, you may get a cached result. To avoid this, add a unique ID to the URL:

    xhttp.open("GET", "demo_get.asp?t=" + Math.random());

    xhttp.send();

    So I tried:

    url":"\"https://www.mysite.be/testjson/MyDictionary.json?t=" & random(1000)"

    But with no effect on the caching.

    Wim

  • The caching doesn't seem the (only or main) reason. I discovered where to find the cached json-file (https://developer.chrome.com/docs/devtools/storage/cache/) and deleted the json-file (and even all the other cached files). But I still get the data from the old json file. Even after closing the tab and restarting the application. I still get the old data. This old data doesn't exist anymore at this point, so where is he getting this data??

    Wim

  • Like I mentioned, is most likely server side.

    Routers also have the ability to cache requests in some scenarios to save bandwidth, this may happen in a commercial or institutional setting, unlikely for home internet though.

  • The caching doesn't seem the (only or main) reason. I discovered where to find the cached json-file (https://developer.chrome.com/docs/devtools/storage/cache/) and deleted the json-file (and even all the other cached files). But I still get the data from the old json file. Even after closing the tab and restarting the application. I still get the old data. This old data doesn't exist anymore at this point, so where is he getting this data??

    Wim

    Are you sure your referencing the right dictionary? It appears you have 2.

    The one getting loaded at the start is not the same as the one you load manually.

  • Lennaert,

    Thank you for your response.

    I started with one dictionary, but added a second one, just to be sure I don't display the data from the first dictionary. So I know yes.

    Wim

  • Can you post an example project and server file with the problem ?

    I'll upload to my server and test it.

  • I tried everything to clear all data, but still Chrome keeps finding old files, for example an old version of c3runtime.js:

    - Deleted the sw.js and offline.json files from the server, to be sure Chrome doesn't save the app for offline use.

    - With Crome Dev Tools cleared all files in storage, cached-storage, ...

    - Cleared all browsing data, history, ...

    - Even changed the directory of the app on the server

    Reloaded with Ctrl+Shift+R, and still Chrome used old files that didn't exist anymore.

    But I've found the solution in the end: incognito-modus.

    + force a reload of the json file by adding ?t=" & random(1000) to the URL.

    Thank you all for your help!

    My working code:

    Wim

  • Like I mentioned, is most likely server side.

    Routers also have the ability to cache requests in some scenarios to save bandwidth, this may happen in a commercial or institutional setting, unlikely for home internet though.

    I'm at a home network, my router can't cache sites.

  • Only possibility left is your web host server settings then.

  • Only possibility left is your web host server settings then.

    The main problem seemed to be a 'hidden' (I couldn't find it) cashing of files in Google Chrome, 'incognitomodus' of Chrome solved my problem.

    Thanks for your help!

    Wim

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)