PHP:
Below is the data retrieved from SERVER
date_default_timezone_set('America/Chicago'); // CDT
echo '
Server Timezone : ' . date_default_timezone_get() . '
';$current_date = date('d/m/Y == H:i:s ');
print "
Server Time : " . $current_date . "
";$dataObject = $_POST; //Fetching all posts
echo "
"; //making the dump look nice in html.
var_dump($dataObject);
echo "
";//Writes it as json to the file, you can transform it any way you want
$json = json_encode($dataObject);
file_put_contents('your_data.txt', $json);
?>
JS:
$(document).ready(function(){
localStorage.clear();
$("form").on("submit", function() {
if(window.localStorage!==undefined) {
var fields = $(this).serialize();
localStorage.setItem("eloqua-fields", JSON.stringify( fields ));
alert("Stored Succesfully");
$(this).find("input[type=text]").val("");
alert("Now Passing stored data to Server through AJAX jQuery");
$.ajax({
type: "POST",
url: "backend.php",
data: fields,
success: function(data) {
$('#output').html(data);
}
});
} else {
alert("Storage Failed. Try refreshing");
}
});
});
注意:如果您希望使用HTML格式的JSON数据,请将your_data文件的文件格式替换为PHP代码中的HTML.