Egret and HTTP requests (Ajax, XMLHttpRequest, Post, Get)

Source: Internet
Author: User

An HTTP request

Two Ajax and XMLHttpRequest

31 Examples of Ajax

The egret.httprequest in four Egret

Five post and get differences

An HTTP request

HTTP in layman http://www.cnblogs.com/yin-jingyu/archive/2011/08/01/2123548.html

HTTP request return Code http://blog.chinaunix.net/uid-25311424-id-3052306.html

Two Ajax and XMLHttpRequest

Based on the Ajax HTTP request description of W3school:

AJAX uses Http requests

In traditional JavaScript programming, if you want to get any information from a file or database on a server, or send a message to the server, you must take advantage of an HTML table-one-way server get or POST data. Users then need to click the Submit button to send/Receive information, wait for the server to respond, and a new page will load the results.

Because the server will return a new page each time the user submits the input, the traditional Web application becomes slow and less friendly.

By using AJAX, your JavaScript communicates directly with the server through JavaScript's XMLHttpRequest object.

By using an HTTP request, a Web page can make a request to the server and get a response from the server without loading the page. The user can stay on the same page, and he or she will not notice that the script has requested the page in the background or sent data to the server.

XMLHttpRequest Object

By using the XMLHttpRequest object, the Web developer can update the page from the server after the page has been loaded!

AJAX was promoted by Google in 2005 (Google Suggest).

Google recommends using the XMLHttpRequest object to create a highly dynamic Web interface: When you start entering a query in Google's search box, JavaScript issues the words to a server, and the server returns a series of search suggestions.

XMLHttpRequest objects are supported by the following browsers: Internet Explorer 5.0+, Safari 1.2, Mozilla 1.0/firefox, Opera 8+, and Netscape 7.

31 Examples of Ajax

Index.html

<script>varXMLHTTP; function Submit (score) {if(Window. XMLHttpRequest) {//code for ie7+, Firefox, Chrome, Opera, SafariXMLHTTP =NewXMLHttpRequest (); }        Else{//code for IE6, IE5XMLHTTP =NewActiveXObject ("Microsoft.XMLHTTP"); } Xmlhttp.onreadystatechange=function () {if(xmlhttp.readystate==4&& xmlhttp.status== $) {console.log (xmlhttp.responsetext); }} xmlhttp.open ("POST","ajax.php",true); Xmlhttp.setrequestheader ("Content-type","application/x-www-form-urlencoded"); Xmlhttp.send ("fname="+score); } Submit (999);</script>

ajax.php

<? php    echo $_post['fname'];? >

The egret.httprequest in four Egret

Official HTTP Tutorial: http://edn.egret.com/cn/index.php/article/index/id/589

Get mode

varRequest:egret. Httprequest;request =NewEgret. HttpRequest ();Request.responsetype =Egret. Httpresponsetype.text;Request.addeventlistener (Egret.Event.COMPLETE, This. Onpostcomplete, This);Request.addeventlistener (Egret. Ioerrorevent.io_error, This. Onpostioerror, This);
This. Request.open ("http://www.xxxx.com?data=123", Egret. Httpmethod.get);
This. Request.setrequestheader ("Content-type","application/x-www-form-urlencoded");
This. Request.send ();
PrivateOnpostcomplete (E:egret. Event):void{
 var< Span class= "PLN" > request = < egret. Httprequest>event.     egret. ( "get data : " , Request. Response             


private Onpostioerror (E:egret. ioerrorevent):void{

}

Post mode

varRequest:egret. Httprequest;request=NewEgret. HttpRequest (); Request.responsetype=Egret. Httpresponsetype.text;request.addeventlistener (Egret.Event.COMPLETE, This. Onpostcomplete, This); Request.addeventlistener (Egret. Ioerrorevent.io_error, This. Onpostioerror, This); This. Request.open ("http://www.xxxx.com", Egret. Httpmethod.post); This. Request.setrequestheader ("Content-type","application/x-www-form-urlencoded"); This. Request.send ("P1=POSTP1&P2=POSTP2"); PrivateOnpostcomplete (E:egret. Event):void{    varRequest = <egret. Httprequest>Event. Currenttarget; Egret.log ("Post data:", Request.response); } PrivateOnpostioerror (E:egret. Ioerrorevent):void{ }

The difference between five post and get

Baidu experience the difference between the get and post submission methods http://jingyan.baidu.com/article/d3b74d64abbd6b1f76e60947.html

Egret and HTTP requests (Ajax, XMLHttpRequest, Post, Get)

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.