Ajax submits data to the backend php for receiving (implementation), ajax backend
After reading the data online for a long time, I found that using ajax to submit data to the background is actually very simple, but many of the explanations are not clear. For Beginners, many of them are really confused and can be used directly, I want to know what is going on. In fact, Using ajax to submit data to the background is very simple.
$. Ajax ({type: "POST", url: "register. php ", data:" name = John & location = Boston ", success: function (msg) {alert (" Data Saved: "+ msg );}});
First of all, let's interpret the above Code. Of course, jQuery is needed to use ajax.
Type: "POST", which is the type of submission
Url: "register. PHP", which is the submission direction. I submitted it to register. php for processing.
Data: "name = Jhon & location = Boston". This is the data we submit. Jhon and Boston are the data we submit.
Success: function (msg)
{
Msg is the data that is returned after the submission is successful.
}
How to write the data in the background to obtain the data:
<? Php // first obtain the data $ username =$ _ POST ['name']; $ password =$ _ POST ['location']; echo $ password;?>
We can clearly see that $ _ POST ["name"]; is to get all Jhon
$ _ POST ['location'] is the obtained Boston
The data we return in the background, that is, the echo data, that is, Boston.
Hope to help you.
The above ajax data submitted to the backend for receiving (implementation method) is all the content shared by the editor. I hope to give you a reference, and I hope you can provide more support to the customer's house.