Javascript errors only on refresh / initial connection.

Javascript errors only on refresh / initial connection.

rhytnenrhytnen Posts: 6Questions: 1Answers: 0

I have a very simple bottle app (flask-alike server) to serve logs. I have noticed the following 3 behaviors:
1. If you clear the javascript cache - the first time you connect to the page, it will show a invalid json response popup.
2. Afterwards you can hit enter in the address bar and things work exactly normally and all data is present (though the xhr response shows a json parse error - I think this may be b/c the string is too long to display in the dev tools console)
3. If you refresh the page, no data is present and the response shows nothing.

In all 3 cases the webserver is showing that it's responding with identical data. I am able to parse the json and believe the data is valid.

Anyone have some experience with these issues?

Answers

  • kthorngrenkthorngren Posts: 20,299Questions: 26Answers: 4,769

    The place I would start is be grabbing the JSON response in the browser's network tools. The link provide in the JSON error will provide the steps:
    https://datatables.net/manual/tech-notes/1

    Copy that and paste in https://jsonlint.com/ and click validate. What are the results?

    If you see escaped quotes (\") in your JSON data then likely its a JSON string when you use json.dumps() when sending the response.

    Kevin

  • rhytnenrhytnen Posts: 6Questions: 1Answers: 0

    Update: This appears to be related to content length. After about 140 rows, the problem beings to occur intermittently and around 200 it's guaranteed to occur.

    I'm using ajax to fetch the data - maybe I need to start doing server side processing to cut down the payload (currently only have around 5000 rows of data though).

  • rhytnenrhytnen Posts: 6Questions: 1Answers: 0

    Sorry kthorngren - i should have been clearer. My 2 sources of data are the xhr tab in dev tools and the output from my webserver.

    When I mentioned "no data is present" and "response shows nothing", that is from the network tab in developer tools.

  • kthorngrenkthorngren Posts: 20,299Questions: 26Answers: 4,769

    When I mentioned "no data is present" and "response shows nothing", that is from the network tab in developer tools.

    If there is nothing in the response tab then I would speculate there is a server issue returning the data. What is the status code when you look at the Headers tab?

    I would suggest setting up your query to return one row of data. Get that working with Datatables then work your way back up to the full data set.

    Kevin

  • rhytnenrhytnen Posts: 6Questions: 1Answers: 0

    I did that before posting. At 140 rows, it begins to show this null response (webserver shows it sent identical data). By 200 rows, it will happen 100% of time.

    Interestingly, this is only a problem refresh. Hitting enter in the address bar for example, will always work.

  • rhytnenrhytnen Posts: 6Questions: 1Answers: 0

    The response header is:
    HTTP/1.1 304 Not Modified
    Date: Fri, 17 Aug 2018 21:25:07 GMT

    I wonder if that means the webserver hasn't cached the data and therefore can't reload it.

  • rhytnenrhytnen Posts: 6Questions: 1Answers: 0

    This is it, I am returning 200s by hand as a test and the problem goes away.

  • kthorngrenkthorngren Posts: 20,299Questions: 26Answers: 4,769

    I am returning 200s by hand as a test and the problem goes away.

    I'm not sure where or if its documented or if I just remember seeing it on the forum but I think Datatables expects both a 200 status code and a valid JSON otherwise you will get the invalid JSON message.

    Kevin

This discussion has been closed.