Append Json Array From Localstorage To Json File On Server
I have a json file in localstorage and i have assigned that json to a variable with javascript so that i can access that with php. Now i want to append the values of that json file
Solution 1:
First we have to understand 3 core concepts here:
- Your javascript lives in the browser of your local computer(clientside).
- Your PHP runs on the remote server(serverside).
- The life circle of a web-app gets executed in requests(each time you send/getsomething from your browser).
You can't directly communicate them in realtime out of the box. You can however, send a request from your javascript(clientside) to your server(serverside).
Using JQuery its quite easy. In your javascript file you do:
$.post('/yoursite.com/your_php_script.php', lstore);
That will send an AJAX request to your server. Now in your_php_script.php you have to capture the content of that JSON.
$data = json_decode(file_get_contents('php://input'));
This reads the JSON from the body of the request you just sent.
You might want to use Chrome dev-tools and check out the network tab. There you can see all the information about the request. Good luck!
Post a Comment for "Append Json Array From Localstorage To Json File On Server"