Home > Web Front-end > JS Tutorial > body text

How to use php to receive data submitted to the background by ajax

php中世界最好的语言
Release: 2018-03-31 15:11:25
Original
2132 people have browsed it

This time I will show you how to use php to receive the data submitted to the background by ajax, and how to use php to receive the data submitted to the background by ajax. What are the precautions? The following is a practical case. , let’s take a look.

I have been reading online for a long time and found that it is actually very simple to use ajax to submit data to the backend, but many of the explanations are not clear. For beginners, many of them are really a bit confusing. I use it directly, but I want to understand what's going on. In fact, it is very simple to use ajax to submit data to the background.

$.ajax({
 type: "POST",
 url: "register.php",
 data: "name=John&location=Boston",
 success: function(msg){
  alert( "Data Saved: " + msg );
 }
});
Copy after login
First of all, let’s interpret the above string of codes. Of course, what you need to use ajax is

jQuery

type: "POST", which is the type of submission

url: "register.PHP", is the direction of submission, I submitted it to register.php for processing
data: "name=Jhon&&location=Boston", this is the data we submitted, Jhon and Boston are what we submitted Uploaded data
success:function(msg)
{
msg is the data returned after successful submission
}

How to write in the background to obtain these data :

<?php
//首先是获取到了数据
$username=$_POST[&#39;name&#39;];
$password=$_POST[&#39;location&#39;];
echo $password;
?>
Copy after login
What we clearly see is $_POST["name"]; which is the Jhon

$_POST[ 'location'] is the obtained Boston

The data returned by our background, that is, the data echoed out, is Boston.

I hope to be helpful.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

AJAX detects the entered user name without refreshing

Ajax cross-domain problem Detailed graphic explanation (with code)

The above is the detailed content of How to use php to receive data submitted to the background by ajax. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template