How does JavaScript send requests to the server?

Source: Internet
Author: User

the XMLHTTPRequest object is used to send HTTP requests to the server in Javascript. Other libraries such as jquery should encapsulate HTTP requests on this object, use the following statement to create an xmlhtprequest object:

Function createxmlhttprequest () {var XMLHTTP; If (window. XMLHttpRequest) {XMLHTTP = new XMLHttpRequest (); If (XMLHTTP. overridemimetype) XMLHTTP. overridemimetype ('text/xml');} else if (window. activexobject) {try {XMLHTTP = new activexobject ("msxml2.xmlhttp");} catch (e) {try {XMLHTTP = new activexobject ("Microsoft. XMLHTTP ") ;}catch (e) {}} return XMLHTTP;} sends a GET request and Asynchronously processes XMLHTTP = createx Mlhttprequest (); var url = "getfiledetail. jsp? Fileid = "+ ID; XMLHTTP. open ("get", URL, true); // XMLHTTP is returned for asynchronous processing. onreadystatechange = callback; XMLHTTP. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded;"); XMLHTTP. send (); send POST request var url = "getnginxstatus"; XMLHTTP. open ("Post", URL, true); XMLHTTP. onreadystatechange = getstatusback; XMLHTTP. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded;"); XMLHTTP. send (XML );

 

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.