Jump to content

need help how to save a json file


robb28

Recommended Posts

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

 

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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 );

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.