trouble reading in a saved state from a database
trouble reading in a saved state from a database
Mwhite007
Posts: 36Questions: 8Answers: 0
in StateRestore
I am able to save a new state into the MS SQL database, but i get an json format error when reading it back in. the dump of the data returned looks like
I am not sure of the exact format the data needs to be in for stateRestore to use
This question has an accepted answers - jump to answer
Answers
That looks about right - for example (note my example here has
stateas a JSON string, but just plain JSON is fine as well):What is the exact error please? Also can you use your browser's developer tools to get the raw response from the server and show me what that is?
Thanks,
Allan
there is nothing returned in developer tools except the dump i showed you. the processing stops at my processing page with this popup:

when I press ok, it continues the page. can't find anything that pinpoints where in the json response it fails... I created a new saved state so now i have two in the array. it seems that it immediately tries to load the saved states but fails with the same "Error in JSON response"
Are you able to PM me a link to the page to I can take a look?
One possibility is that the response includes a UTF8 BOM which are hidden characters to define the character set. That can cause invalid JSON.
Allan
i tried forcing UTF-8 but it didn't seem to make any difference. i don't see how i can set up a demo because it's a ColdFusion server. i haven't uploaded the code to production yet and that server is locked down anyway.
This is the code in DataTables that is triggering the error message to be shown:
If you put a breakpoint on that
ifcondition, and then when it hits it, you could inspectresponseDataand see what that is. It should be a JSON string.Possibly another option, in the Chrome network inspector, view the "Response" tab for that Ajax request - it might show what is causing it to not be valid JSON (Firefox has a similar option).
Allan
I'm not sure what tool is displaying your first screenshot. Don't know the browser you are using but in Chrome, for example, you can view the raw response Under Developer Tools > Network > Response. You can paste the raw response to a site like https://jsonlint.com/ to validate the JSON response. Or you can paste it here or PM Allan with the raw data. If the Response tab is empty then it would seem the JSON data is not being populated into the response at the server.
Kevin
the screenshots provided were from the Brave browser developer tool network pane, preview tab. there was actually nothing in the pane so i had to put a "CFDUMP" command to show the FORM and results data.
here is the DataTable section in the javascript file for stateRestore:
in the StateProcess.cfm file I put a basic switch statement to handle the read and create function:
you can see that it calls the readStates function in utility2 file:
I'm strongly suspecting that there is a UTF-8 BOM at the start of the response from the server, which would result in the response being invalid JSON.
Were you able to put a breakpoint at the point in the code that I noted above? If you do that, what does:
show in the browser's console? (Note you'll need to be loading the non-min code in order to be able to easily find that second of the code!).
Allan
when i put a breakpoint at line 84070 if statement, the responseData is the html page, not the result of the call:
ok, i think i got it... the StateProcess.cfm page needed to only output the json data. i removed all the html on that page and added:
so now when the stateRestore calls StateProcess.cfm page with state-read the only content is the json string
Ah! The end point was mixing the HTML and the JSON - yup, that would do it. Great to hear you found and resolved the problem
.
I haven't played around with Brave much - I'm going to have a look at its JSON viewer now, it could be useful!
Allan