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 ); } });
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; ?>
$_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!