JavaScript Ajax-2 Ajax (use Ajax to send GET requests, use AJAX to send post requests)

Source: Internet
Author: User

Tag: Browser server string User false

One, using Ajax to send a GET request


Steps to send an asynchronous request

-Get Ajax object: Get XMLHttpRequest Object instance

-Create Request: Call the Open method of the XMLHttpRequest object

-Set the callback function: Set the response function for the onreadystatechange event of the Ajax object

-Send request: Call the Send method of the Ajax object

-Get Ajax object 650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/7E/7A/wKioL1cCJXDQVmhbAAEuwaWAOB8358.png " Title= "Web.png" alt= "Wkiol1ccjxdqvmhbaaeuwawaob8358.png"/>

-Create Request

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7E/7A/wKioL1cCJbSRucYPAAAv5KuoQ64196.png "title=" Web.png "alt=" Wkiol1ccjbsrucypaaav5kuoq64196.png "/>

Note

-true: Indicates the sending of an asynchronous request (the user can still do other things to the current page when the Ajax object sends the request)

-False: Indicates the sending of a synchronization request (when the Ajax object sends a request, the browser locks the current page and the user cannot do anything else on the current page)

-Set callback function

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7E/7D/wKiom1cCJhOxuiaCAADLnaQvY9I426.png "title=" Web.png "alt=" Wkiom1ccjhoxuiacaadlnaqvy9i426.png "/>

-Send Request

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7E/7D/wKiom1cCJqqz2pd9AAEROToh3Mo703.png "title=" Web.png "alt=" Wkiom1ccjqqz2pd9aaerotoh3mo703.png "/>

Writing server-side code

-The server typically returns part of the data, such as a simple text

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7E/7A/wKioL1cCJ-OydzBTAAAxVjrve5Q511.png "title=" Web.png "alt=" Wkiol1ccj-oydzbtaaaxvjrve5q511.png "/>


Second, use Ajax to send a POST request


Send string

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7E/7D/wKiom1cCKDzDmJ31AAEzfU7oWIg296.png "title=" Web.png "alt=" Wkiom1cckdzdmj31aaezfu7owig296.png "/>

-POST Request:

-Need to manually set the request message header to application/x-www-form-urlencoded

-A commit parameter is passed within the Send method, and no nullable


Summary: This chapter focuses on Ajax (using AJAX to send a GET request, using AJAX to send a POST request)


This article from the "Flying Ants" blog, declined to reprint!

JavaScript Ajax-2 Ajax (use Ajax to send GET requests, use AJAX to send post requests)

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.