Hi Everyone i'm Rick 22 years and I'm new here. i got a problem I do not fully understand it what i have to do. can someone help me with this? what i have to do is this: Never create JSON strings manually, use JSON.stringify for this. and he is talking about this code: function saveState() { submitData('[{"lane 1": ' + getLaneState('lane1') + ',"lane 2": ' + getLaneState('lane2') + ',"lane 3": ' + getLaneState('lane3') + ',"lane 4": ' + getLaneState('lane4') + '}]'); } Code (markup): is this what i have to do? : function saveState() { var myJSON = JSON.stringify(obj); var obj = submitData('[{"lane 1": ' + getLaneState('lane1') + ',"lane 2": ' + getLaneState('lane2') + ',"lane 3": ' + getLaneState('lane3') + ',"lane 4": ' + getLaneState('lane4') + '}]'); } Code (markup):
Hello Rick I think you have to explain more. Assuming what the submitData() function does is to return a JSON object, then yes you may execute var myJSON = JSON.stringify(obj); Code (JavaScript): AFTER submitData() line but not before it.
its a function function submitData(data) { var xhr = new XMLHttpRequest(); var url = "savestate.php"; xhr.open("POST", url, true); xhr.setRequestHeader("Content-Type", "application/json"); xhr.onreadystatechange = function () { if (xhr.readyState === 4 && xhr.status === 200) { console.log(xhr.responseText); } }; xhr.send(data); } function saveState() { var myJSON = JSON.stringify(obj); var obj = submitData('[{"lane 1": ' + getLaneState('lane1') + ',"lane 2": ' + getLaneState('lane2') + ',"lane 3": ' + getLaneState('lane3') + ',"lane 4": ' + getLaneState('lane4') + '}]'); } Code (markup):