AJax
<script type="text/javascript">
var data = {
id:"1";
name:"test";
};
$.ajax({
url:'/api.php?action=edit',
type:'POST',
contentType:'application/json;charset=utf-8',
dataType:'json',
// Data must be JSON formatted
data: JSON.stringify(data),
success:function(result) {
// do something
},
error:function() {
// do something
},
});
</script>
PHP
<?php
$data= json_decode(file_get_contents('php://input'), true);
?>
Reference
https://imququ.com/post/four-ways-to-post-data-in-http.html
https://api.jquery.com/jquery.ajax/
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
https://www.php.net/manual/en/wrappers.php.php#wrappers.php.input