1. Requirements
You want to create a login verification page. There are several requirements.
A. No jump
B. Use php for verification in the background.
2. Process
Click "Log on" Key ----> (jquery) to obtain the input value and send a POST request -----> to logingverify. php -------> return the verification result to jquery ----> call the callback function to display the result.
3. Highlights
JQuery:
- $("#signin_submit").click(function(e){
- e.preventDefault();
- var id = $("#username").val();
- var pwd = $("#password").val();
- var url = "login/loginverify.php";
- $.post(url,{name:id,password:pwd},function(data,status){ $("#result").html(data);});
- });
In this Code, the # username and # password values are obtained first.
Then, two values are sent to login/loginverify. php through post.
$.post(URL,data,callback);
The url value is "login/loginverify. php", and the sent data is {name: id, password: pwd}
The subsequent function (data, status) is the callback function. After receiving the post return value, this method updates the content of # result to the result.
PHP:
- <?php
- $name = $_POST['name'];
- if($name == "test")
- echo "Success";
- else
- echo "Failed";
- ?>
First, JQuery sends a POST request to it, so we can get the POST content in JQuery just now through $ _ post ['fieldname.
Here we get $ name to determine whether its value is "test ".
If yes, output Success; otherwise, output Failed.
It is worth noting that the callback function in Jquery just now has two parameters: data and status. what we echo is actually returned as data, and the status value, because the php is correctly executed, no matter whether we return Success or Failed, the status parameter is actually success.