Let's put examples to demonstrate my problem:
index.html:
<!doctype html>
<html>
<head>
<title>Testing XHR</title>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
</head>
<body>
<script>
$(function()
{
const test = "This is a test text.";
$.post("test.php", {data: test}, function()
{
console.log(test);
});
});
</script>
</body>
</html>
test.php:
<?php
var_dump($_POST);
So, when I load index.html
, it completes $.post()
request successfully. I have checked it via Chrome's "Inspect" option, under "Network" tab. But when I load test.php
, it shows empty string. I have tested it to my local server and a live server, results are the same. What am I doing wrong?