write stock in data folder using post requests
This commit is contained in:
parent
68029d4eb4
commit
c4e6bd641b
3 changed files with 51 additions and 3 deletions
|
@ -42,10 +42,10 @@ ob_start();
|
||||||
<input type="text" class="form-control" id="imageInput" placeholder="Lien Image">
|
<input type="text" class="form-control" id="imageInput" placeholder="Lien Image">
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<button type="submit" class="btn btn-success" onclick="addNewItem()"><i class="fas fa-check"></i></button>
|
<button type="submit" class="btn btn-success" onclick="addNewItem()"><i class="fas fa-check"></i>
|
||||||
|
</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
@ -55,8 +55,17 @@ ob_start();
|
||||||
<?= $tableHeader ?>
|
<?= $tableHeader ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<div style="display: flex; margin-top: 100px">
|
||||||
|
<button class="btn btn-success btn-lg" style="margin: auto"
|
||||||
|
onclick="saveDataset()">
|
||||||
|
Sauvegarder le stock
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</>
|
||||||
|
|
||||||
<link type="text/css" rel="stylesheet" href="<?= $relativePath ?>assets/css/stock.css" media="screen,projection"/>
|
<link type="text/css" rel="stylesheet" href="<?= $relativePath ?>assets/css/stock.css" media="screen,projection"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
18
admin/write_json.php
Normal file
18
admin/write_json.php
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
$rest_json = file_get_contents("php://input");
|
||||||
|
$_POST = json_decode($rest_json, true);
|
||||||
|
|
||||||
|
|
||||||
|
//var_dump($_POST);
|
||||||
|
|
||||||
|
$fp = fopen('../data/stock.json', 'w');
|
||||||
|
$result = fwrite($fp, json_encode($_POST));
|
||||||
|
fclose($fp);
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
echo 'Réussite !';
|
||||||
|
} else {
|
||||||
|
echo 'Echec!
|
||||||
|
'; // Allows to create a newline
|
||||||
|
var_dump($_POST);
|
||||||
|
}
|
|
@ -174,3 +174,24 @@ function isItemInputFilled() {
|
||||||
$.selector_cache('#imageInput').val() !== '' &&
|
$.selector_cache('#imageInput').val() !== '' &&
|
||||||
getTypesChecked().length > 0;
|
getTypesChecked().length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function saveDataset() {
|
||||||
|
let finalDataset = {
|
||||||
|
types: defaultTypes,
|
||||||
|
articles: currentDataset
|
||||||
|
};
|
||||||
|
console.log(finalDataset);
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: "write_json.php",
|
||||||
|
data: JSON.stringify(finalDataset),
|
||||||
|
dataType: "json",
|
||||||
|
contentType: "application/json; charset=utf-8",
|
||||||
|
complete: function (data) {
|
||||||
|
alert(data.responseText);
|
||||||
|
console.log(data);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue