我需要将值从AJAX发送到JSON文件,所以我将其分为两步
我无法在保存它的同一页上读取JSON文件的问题
将值从AJAX发送到PHP文件(IT WORKS FINE)
$.ajax({
url: 'php.php',
type: 'POST',
data: {id:value},
success: function(data) {
console.log(data);
}
});
<?php
$collectionID = file_get_contents('json.json');
//This php code is in the same page of AJAX, my problem that it doesn't read json at the same time.
//I must refresh the page to read the old value then the AJAX save a new value and I can't read it also now
?>
php.php文件 - 将值写入json文件(IT WORKS FINE)
file_put_contents('json.json', $_POST['id']);
我需要从AJAX(UP)发送并保存该值,然后在同一页面再次将其读入我的PHP代码(DOWN)!!!
我需要这样做,因为我不能直接从JS向PHP发送值,所以我从客户端(JS)发送它,然后我收到服务器端(PHP)..现在我想收到它回到客户端(PHP)以回显值