index.html Copy code The code is as follows: < head> jQuery Ajax Demonstration <br>$(document).ready(function(){//This is jQueryready, it is like main in C language. The operation is contained in it <br>$("#button_login").mousedown(function(){ <br>login(); //The function login() is triggered after clicking the button with the ID "button_login"; <br>} ); <br>}); <br>function login(){ //Function login(); <br>var username = $("#username").val();//Get the username in the box<br>var password = $("#password").val();//Get the password in the box<br>$.ajax({ //An Ajax process<br>type: "post", //With post Method to communicate with the backend<br>url: "login.php", //Communicate with this php page<br>dataType:'json',//The value returned from php is interpreted in JSON mode<br>data: 'username= ' username '&password=' password, //There are two items of data sent to php, namely u and p passed above <br>success: function(json){//If the call to php is successful<br>//alert (json.username 'n' json.password); //Alert the return value (json.username) in php <br>$('#result').html("Name:" json.username "< ;br/>Password:" json.password); //Display the return value in php at the predefined result locator position <br>} <br>}); <br>//$.post() Method: <br>$('#test_post').mousedown(function (){ <br>$.post( <br>'login.php', <br>{ <br>username:$('#username' ).val(), <br>password:$('#password').val() <br>}, <br>function (data) //Return function<br>{ <br>var myjson=' '; <br>eval('myjson=' data ';'); <br>$('#result').html("Name 1:" myjson.username "<br/>Password 1:" myjson .password); <br>} <br>); <br>}); <br>//$.get() method: <br>$('#test_get').mousedown(function () <br> { <br>$.get( <br>'login.php', <br>{ <br>username:$('#username').val(), <br>password:$('#password') .val() <br>}, <br>function(data) //Return function <br>{ <br>var myjson=''; <br>eval("myjson=" data ";"); <br>$('#result').html("Name2:" myjson.username "<br/>Password2:" myjson.password); <br>} <br>); <br>}) ; <br>} <br> Enter name: Enter password: ajax submit postsubmit getsubmit