Home > Web Front-end > JS Tutorial > ajax submits data to background php for reception_AJAX related

ajax submits data to background php for reception_AJAX related

微波
Release: 2017-06-28 13:55:06
Original
1146 people have browsed it

The following editor will bring you an article about ajax submitting data to the backgroundphpreceiving (implementation method). The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor and 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 It looks a bit confusing, so I use it directly, but I also want to understand what's going on. In fact, it is very simple to use ajax to submit data to the backend.

$.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.

The above is the detailed content of ajax submits data to background php for reception_AJAX related. 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