Ajax Failing To Load Json

  • Hi

    It's been a while now that I'm having this weird bug that the Ajax fails to load the JSON, especially when you first run the Game for the first time through the website, it fails always but if you keep refreshing it will load it at the end.

    Two Notes:

    1-It doesn't happen on C3 preview

    2-I cannot replicate on an empty project, I grabbed my Json file from my main project and put it on an empty project then uploaded it to my website and it works. Not sure why it only happens on my main project, there are no events just the Ajax loading and nothing else on the layout that loads the Ajax and also there no many assets just one Background and a few small pictures so I don't see why it would fail on my main project.

    Any ideas what it can be?

    Here is the Console Log Error:

    I'm using R251.2 stable

    Update:

    I just tested R259 and it fails less but still fails example at the 12 try

  • Can you show a screenshot of your events where you request and load this JSON?

  • Can you show a screenshot of your events where you request and load this JSON?

    Hi Doop

    Sure, I forgot to leave a picture of the events here you go.

    As you can see they are all correct, I normally use Ajax all the time I know there is nothing wrong with the events. I have a feeling that it could be the bug that was fixed a while back here or maybe a new one but it's hard to reproduce on an empty project even using the same JSON that is failing.

    https://www.construct.net/en/forum/construct-3/general-discussion-7/ajax-request-failure-beta-r228-157055/page-3

    The problem only fails with this JSON in particular, not sure if it will help but is a 16MB JSON file that contains a lot of data compressed with base64.

    This layout has nothing else just those events and there is nothing else that it could interfere.

  • Are you sure Play.Data_Ready is False by default and you are not switching to another layout before AJAX loads the file? This is the only thing that potentially can be wrong with your code.

    Maybe 16MB file is just too much for Construct. Try expanding all branches in that error message in console log, maybe you'll find something there.

    Are you saying this only happens with the exported game? Maybe it's a problem with your web server.

  • Are you sure Play.Data_Ready is False by default and you are not switching to another layout before AJAX loads the file? This is the only thing that potentially can be wrong with your code.

    Maybe 16MB file is just too much for Construct. Try expanding all branches in that error message in console log, maybe you'll find something there.

    Yep, that is all good and checked:

    The Play.Data_Ready is False always

    Also, it cannot go to the next layout as "Play.Data_Ready" it becomes Active only after it loads the Array from Ajax so that's not possible that it can move to the next layout before it loads the Array.

    I blocked just in case the events for changing to the next Layout so there is no more layout change, just the Array loading from Ajax and still failed so definitely is not because it was changing the layout, at least I can discard that option.

    The only thing that I think could be the cause maybe is that I'm testing in Browsers incognito mode? not sure if they are any known problems using incognito mode but I need to test there to clear the cache.

    Are you saying this only happens with the exported game? Maybe it's a problem with your web server.

    Yeah, maybe that's what I thought too as it doesn't happen on preview, not sure what else it could be, I just have the C3 files there but I will keep looking, I use Cloudflare so not sure if that could cause any problem.

    The logs didn't help much:

    Thanks for your help

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I would try adding more data to the file, maybe increasing its size to 20+ MB. See if this makes the problem worse, or if will allow to reproduce it in a test project. Or maybe try a different web service.

    Once you can pinpoint what exactly is causing this issue, it will be easier to figure out a solution.

  • I did a search for net::ERR_CACHE_WRITE_FAILURE and it seems to be related with the browser not being able to cache very large files.

    Is your server gzipping and minifying the json? If the file is being served as is, that might help.

    You can also try an incognito mode tab to see if it works there.

  • I did a search for net::ERR_CACHE_WRITE_FAILURE and it seems to be related with the browser not being able to cache very large files.

    Is your server gzipping and minifying the json? If the file is being served as is, that might help.

    You can also try an incognito mode tab to see if it works there.

    Hi Diego Thank you

    I think you're right looks like it could be something about the size as I found things like this

    Link: https://soorajchandran.medium.com/speeding-up-your-website-using-prefetching-techniques-8077058b7418

    There is not much info on the internet bout this topic though which I'm surprised

    Also, Is there any limit for JSON files? I never heard anything like that on the forums or Manual that there is a size limitation using Json files loaded through Ajax

    Is your server gzipping and minifying the JSON? If the file is being served as is, that might help.

    Nope, as far I know there isn't any (gzipping or minifying) at least I haven't implemented them when I created the server.

    You can also try an incognito mode tab to see if it works there.

    I always test in incognito mode so it doesn't save the cache and it fails all the time.

    =============================================================================

    The good news is that I managed to reproduce the BUG in a new empty project so I can share it.

    What I did is try to replicate as many settings as possible that I had on my main project and also I increased the Json File to increase the chance for a failure.

    There are no many settings to be honest:

    -I use Custome Loader layout

    So it starts on the "Menu Layout"

    There once it loads the Game it waits 2 secs and moves to the "Game Layou"

    -On the Game layout is where I load the Ajax at the start of the layout

    Where it shows a text message for if it loaded successfully or not

    Console Log Error:

    =================================================

    So here are the Files:

    C3 Project: https://www.dropbox.com/s/l4dccom4ia2oxco/Ajax%20BUG.c3p?dl=0

    If you export it by your self then here is the settings that I use when exporting as HTML

    ====================================

    Or here is the Zip ready

    https://www.dropbox.com/s/6usggrd2q30c78p/Ajax%20BUG.zip?dl=0

    I would really appreciate it if someone can confirm the bug so we can eliminate that is from my server

    Thank you

    Steps To Reproduce:

    Load the zip to your website

    1-Open chrome in incognito mode

    2-Go to the URL wait until it rich the "Game Layout"

    If it shows "Ajax Loaded Successfully!!!!!!!!!" then you need to close the tab and open a new one and try again until it shows

    "Errorrrrrrr Ajax Failed!!!!!!!!" in Red

    For me, it fails every time but you may need to try many times

    Also one more thing important, this problem is not only Chrome related as the error occurs when I test on the iPhones Browser swell.

  • Is this a bug? do I have to open a bug report? or it's a specific problem on my server?

    Can someone confirm, please to see what I need to do next

    Thank you

  • I haven't tried it out, but I am wondering what is that base64 encoded data?

    I tried looking at the json on on it's own in Notepad++ and it struggled to show anything. Taking several seconds to open the file and then scrolling through it as sluggishly as you could possibly scroll.

    I am thinking the data is an image because 16 megabytes of raw text would be a lot of text.

    I know it is tempting to just cram an image in text format in a json file and then just load the json. But in this case maybe it is better to hold an identifier in the json and then use that to load the image through the browser's normal methods.

  • I haven't tried it out, but I am wondering what is that base64 encoded data?

    I tried looking at the json on on it's own in Notepad++ and it struggled to show anything. Taking several seconds to open the file and then scrolling through it as sluggishly as you could possibly scroll.

    I am thinking the data is an image because 16 megabytes of raw text would be a lot of text.

    I know it is tempting to just cram an image in text format in a json file and then just load the json. But in this case maybe it is better to hold an identifier in the json and then use that to load the image through the browser's normal methods.

    Thanks, Diego no worries, just making sure that it doesn't get lost on the forum

    Yes that's an Array encoded to base64 then is saved into another Array as it is, basically, one big normal Array that holds in each X index an Array encoded in base64

    Yes you're right it's quite a lot of data as it was the only way to make this game, there wasn't any other alternative, it needs all that data to make it work.

    Is not an image lol its insane amount of data I know haha but there is no images or anything like that, it is just pure Data that is needed to run the game, it is one of those games that it wasn't meant to be done in construct I realize after but I'm quite happy with the results as all the hard part it's done already, basically the whole game it's done and I'm just finishing the UI which is the last few things left.

    Though once the ajax is loaded it runs very smooth no problems at all, also when it manages to load the JSON it loads quite fast there is no problem either.

    Also, my original JSON file is 16MB only so I had to increase it for this BUG demo to 28MB to make sure you can reproduce it easier.

    Thanks for your help I really appreciate it

  • I'm still looking for solutions if anyone has any ideas.

    I tried looking at all the config on the server but I don't see anything related to this and Google doesn't help much as there is no much info on this topic.

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