Objective: Send the JSON string that resides in localStorage to a text file at the server.
I tried using AJAX and JQuery. Link1 Link2
My code:
JAVA Script
function testAPI() {
FB.api('/me?fields=id,name,email', function(response) {
localStorage.user_data=JSON.stringify(response);
$.ajax({
type: "POST",
url: "https://vtpt.in/~ad/ignore/backend.php",
data: {localStorage.user_data},
success: function() {alert("Data Sent");}
});
});
}
PHP
Below is the data retrieved from SERVER
<?php
$dataObject = $_POST['data']; //Fetching all posts
file_put_contents('user_data.txt', $dataObject , FILE_APPEND | LOCK_EX );
?>