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 ); } });
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['name']; $password=$_POST['location']; echo $password; ?>
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!