Why a bunch of HTML tags appear in the value of the $_ post superglobal variable

submit data to the server with a post request through Ajax, and output the value of the $_ post superglobal variable in PHP. The output is shown in the following figure

:

//demo3.html

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<title>Document</title>

</head>

<body>

    <form action="Demo3.php" method="POST">
    
    :<input type="text" name="username" id="un"><br/>
    
    :<input type="text" name="password" id="pw"><br/>
    
    <input type="submit" id="submit" value="">
    
    </form>
    
    <p id="tips">

</body> </html> <script> var submit_btn = document.getElementById("submit"); var xhr = new XMLHttpRequest(); submit_btn.onclick = function(e){ e.preventDefault(); xhr.onreadystatechange = function(){ if(xhr.readyState==4 && xhr.status==200){ alert(xhr.responseText); } } var username = document.getElementById("un").value; // var data = "username="+username; xhr.open("post","Demo3.php"); xhr.setRequestHeader("Content-Type","application/x-www-form-urlencode"); xhr.send(data); } </script> //Demo3.php <?php echo ($_POST);

is there a god who knows what the problem is?

Mar.14,2021

1. Your ajax test does transfer data to your background Demo3.php, which is correct
2. A bunch of HTML tags appear because it is an error report by the PHP background. You should read the wrong content carefully

.
Notice : Array to string conversion
//echoechovar_dump

3. Ajax does return a result, and that "correct" result is actually on the last line. Array, returns an array object

.

$_ POST is an array and cannot be outputted using echo . You can use print_r ($_ POST); ) to output.


getting an empty array should be the problem of Header headers, and Content-Type should be application/x-www-form-urlencoded . The letter d

is missing.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e99eed-47551.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e99eed-47551.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?