jquery is a packaged JavaScript class library that has its own syntax, and I'll talk about implementing Ajax in the 3 method below jquery. Let's start with the example.
The first method of $. Post (Url,data,callback, type);
First create a new HTML page with the same page layout as in the previous section
The code is as follows:
The code is as follows |
Copy Code |
<table style= "Background-color:lightgreen; margin-top:230px; margin-left:300px "> <tr> <td><label> name:</label> </td> <td> <input id= "txtname1" type= "text"/> </td> </tr> <tr><td><label> Password:</label></td> <td> <input id= "txtpwd1" type= "password"/></td></tr> <tr><td> <input id= "BTNDL1" type= "button" value= "Login" onclick= "Sayhellojquery ()"/></td> <td> <input id= "btnqx1" type= "button" value= "Cancel"/></td></tr> </table> |
Then add the code to the
The code is as follows |
Copy Code |
function Sayhellojquery () { var name = $ ("#txtname1"). Val ();//Get the name of the logged-on person $.post ("Sayhello.ashx", {name:name}, function (data, textstatus) { if (Textstatus = = "Success") { alert (data); } }); Here is the jquery post method to achieve the Ajax effect. |
The Post method has three parameters:
First parameter: Send the URL of the request, this example is "Sayhello.ashx",
Second parameter: The passed parameter data, where the Parameter form is the form of the key value pair: {Key:value,key:value}, in this case passing the name of the logged-on person: {name:name},
The third parameter is an anonymous callback function that has two parameters (Data,textstatus), the parameters are fixed, the first parameter is data, the result returned after Sayhello.ashx page processing, and the second is state, when response's return state is " This method is called when success ".
The fourth parameter is type, which is optional, can be empty, and can be the client's request type JSON, XML, and so on. (because it is an optional parameter, there is no selection)