1, we know that the general form request is this purple
//
<form method="post" action="php.php">
<input type="text" name="username" />
</form>
//
//php.php
$username = $_POST["username"]
2. The native ajax request for the xhr object looks like this:
var xmlhttp = new XMLHttpRequst();
xmlhttp.open("POST","/statics/demosource/demo_post2.php",true);
//name
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("fname=Henry&lname=Ford");
Native ajax post request, is still a mock form, and the backend still obtains the value through the name field of the form
3, HTTP request implemented by $.post ():
//
$.post("web.php", { "username": "lofayo" }, function(data) {
console.log(data)
})
//
//web.php
$username = $_POST["username"]
in fact, I don"t quite understand this. The most original HTTP requests are implemented through forms, and the first three methods are also implemented by simulating form requests, but this kind of release is not a simulated form, but it can still realize HTTP requests. And no matter how the front end requests, the back end obtains the sent data in a unified way
.