I am sending a string and an array to a php file from an AJAX request
My html looks like this
<form>
<input class="description" type="text">
<input type="submit">
</form>
My js file looks like this
$('form').submit(function(e){
e.preventDefault();
var description = $('.description').val();
var fileNames = ['1.jpg', '2.jpg'];
var data = {
description,
fileNames
};
$.ajax({
url: 'details.php',
type: 'POST',
data,
success: function(data){
console.log(data)
}
});
});
My php file looks like this
<?php
$str = file_get_contents("test.json");
// // decode JSON
$json = json_decode($str, true);
$decodedJSON = json_decode($str, true);
var_dump($decodedJSON);
$description = $_REQUEST;
$milliseconds = round(microtime(true) * 1000);
$description->time = $milliseconds;
file_put_contents('test.json', json_encode($description, JSON_PRETTY_PRINT));
?>
This sets the json file as
{"description":"test text entered","SQLiteManager_currentLangue":"2"}
I want the json file to look like where the number is the current time in ms.
{
"1495134004244": {
"images": [
"2.JPG"
],
"description": "test"
}
}