robb28 Posted November 5, 2019 Share Posted November 5, 2019 Hi Everyone, i need some help how can i save this jsonfile to the webserver? my code // Load initial values from JSON 'file' jsonfile = '[{"lane 1":"1","lane 2":"1","lane 3":"5","lane 4":"2"}]'; var initialstate = JSON.parse(jsonfile); setLaneState("lane1",initialstate[0]['lane 1']) setLaneState("lane2",initialstate[0]['lane 2']) setLaneState("lane3",initialstate[0]['lane 3']) setLaneState("lane4",initialstate[0]['lane 4']) Quote Link to comment Share on other sites More sharing options...
requinix Posted November 5, 2019 Share Posted November 5, 2019 Send the JSON to a PHP script on the server using AJAX. The script decodes the JSON, verifies it looks good according to whatever criteria you haven't mentioned are important for this JSON, and then encodes and saves. 1 Quote Link to comment Share on other sites More sharing options...
robb28 Posted November 5, 2019 Author Share Posted November 5, 2019 41 minutes ago, robb28 said: Hi Everyone, i need some help how can i save this jsonfile to the webserver? my code // Load initial values from JSON 'file' jsonfile = '[{"lane 1":"1","lane 2":"1","lane 3":"5","lane 4":"2"}]'; var initialstate = JSON.parse(jsonfile); setLaneState("lane1",initialstate[0]['lane 1']) setLaneState("lane2",initialstate[0]['lane 2']) setLaneState("lane3",initialstate[0]['lane 3']) setLaneState("lane4",initialstate[0]['lane 4']) i have to save it in my folder( where i have my code) Quote Link to comment Share on other sites More sharing options...
requinix Posted November 5, 2019 Share Posted November 5, 2019 Okay. Quote Link to comment Share on other sites More sharing options...
robb28 Posted November 6, 2019 Author Share Posted November 6, 2019 thanks for helping it works now i got 1 more question: i have to use ajax i think the (post methode) what i try to do is the lane 1 2 3 4 is now on 1 1 5 2 but what i want is that if i press on one button that it will be stored on the button I last clicked on. do you know how to use this and where i have to put it in de code? //jsonfile = '[{"lane 1":"1","lane 2":"1","lane 3":"5","lane 4":"2"}]'; var jsonRequest = new XMLHttpRequest(); jsonRequest.onreadystatechange = function () { if (jsonRequest.readyState == 4 && jsonRequest.status == 200) { var initialstate = JSON.parse(jsonRequest.responseText); setLaneStates(initialstate); console.log('Done loading JSON data'); } else { console.log('Failed to get JSON data'); } } jsonRequest.open( "GET", "data.json", true); jsonRequest.send( null ); Quote Link to comment Share on other sites More sharing options...
requinix Posted November 6, 2019 Share Posted November 6, 2019 Where is the PHP script I said you needed to create? Quote Link to comment Share on other sites More sharing options...
maxxd Posted November 7, 2019 Share Posted November 7, 2019 14 hours ago, robb28 said: what i try to do is the lane 1 2 3 4 is now on 1 1 5 2 but what i want is that if i press on one button that it will be stored on the button I last clicked on. I'm sorry, but what? I'm not trying to be an ass, but take a breath, step back, and describe what you want to do one simple step at a time. Write out the pseudo-code, then post it here. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.