In-depth understanding of Ajax get and post requests and ajaxget

Source: Internet
Author: User

In-depth understanding of Ajax get and post requests and ajaxget

1. get request

Function () {// request time to the server // 1. create an asynchronous object (small browser) var xhr = new XMLHttpRequest (); // 2. set the parameter. "true" indicates that the asynchronous mode xhr is used. open ("get", "GetTime. ashx? Name = Mr jing ", true); // 3. make the get request not to obtain the cached data from the browser xhr. setRequestHeader ("If-Modified-Since", "0"); // 3. set the callback function xhr. onreadystatechange = function () {// 3.1 if (xhr. readyState = 4 & xhr. status = 200) {// 3.2 obtain the corresponding style content var res = xhr. responseText; alert (res) ;}; // 4. send asynchronous request xhr. send (null );}

2. post request

Function () {// request time to the server // 1. create an asynchronous object (small browser) var xhr = new XMLHttpRequest (); // 2. set the xhr parameter. open ("post", "GetTime. ashx ", true); // 3. set the encoding format of the Request Message style (set to the default form encoding format) xhr. setRequestHeader ("Content-Type", "application/x-www-form-urlencoded"); // 4. set the callback function xhr. onreadystatechange = function () {// 3.1 if (xhr. readyState = 4 & xhr. status = 200) {// 3.2 obtain the corresponding style content var res = xhr. responseText; alert (res) ;}; // 5. send asynchronous request "name = Mr jing" // 5.1 format: directly splice string key = value & key1 = value2 xhr. send ("name = Mr Jing & age = 18 ");};

The above in-depth understanding of Ajax get and post requests is all the content shared by the editor. I hope to give you a reference, and I hope you can provide more support for the help house.

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.