jquery Implementation Ajax Learning notes (1/3)

Source: Internet
Author: User

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)

Home 1 2 3 last
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.