Can anyone help me with save a jsonfile

Hi Everyone,

i need some help how can i save this jsonfile to my folder {where i have my code’s}?

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'])

Open SSH connection, cd to the save directory, nano, write that JSON, ctrl+x, y, file.json, enter.

thanks for helping i got 1 more question:

i have to use with 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 );
Sponsor our Newsletter | Privacy Policy | Terms of Service