一  Http请求

二  AJax和XMLHttpRequest

三  一个Ajax例子

四 Egret中的egret.HttpRequest

五 Post和Get区别

一 Http请求

Http深入浅出  http://www.cnblogs.com/yin-jingyu/archive/2011/08/01/2123548.html

http请求返回码  http://blog.chinaunix.net/uid-25311424-id-3052306.html

二 Ajax和XMLHttpRequest

根据w3school的AJAX Http请求描述:

AJAX 使用 Http 请求

在传统的 JavaScript 编程中,假如您希望从服务器上的文件或数据库中得到任何的信息,或者向服务器发送信息的话,就必须利用一个 HTML 表单向服务器 GET 或 POST 数据。而用户则需要单击“提交”按钮来发送/获取信息,等待服务器的响应,然后一张新的页面会加载结果。

由于每当用户提交输入后服务器都会返回一张新的页面,传统的 web 应用程序变得运行缓慢,且越来越不友好。

通过利用 AJAX,您的 JavaScript 会通过 JavaScript 的 XMLHttpRequest 对象,直接与服务器来通信。

通过使用 HTTP 请求,web 页可向服务器进行请求,并得到来自服务器的响应,而不加载页面。用户可以停留在同一个页面,他或她不会注意到脚本在后台请求过页面,或向服务器发送过数据。

XMLHttpRequest 对象

通过使用 XMLHttpRequest 对象,web 开发者可以做到在页面已加载后从服务器更新页面!

在 2005 年 AJAX 被 Google 推广开来(Google Suggest)。

Google 建议使用 XMLHttpRequest 对象来创建一种动态性极强的 web 界面:当您开始在 Google 的搜索框中输入查询时,JavaScript 会向某个服务器发出这些字词,然后服务器会返回一系列的搜索建议。

XMLHttpRequest 对象得到下列浏览器的支持:Internet Explorer 5.0+、Safari 1.2、Mozilla 1.0 / Firefox、Opera 8+ 以及 Netscape 7。

三  一个Ajax例子

index.html

<script>
var xmlhttp; function submit(score){ if(window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState== && 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();
</script>

ajax.php

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

四 Egret中的egret.HttpRequest

官方Http的教程:http://edn.egret.com/cn/index.php/article/index/id/589

Get方式

var request: egret.HttpRequest;
request = new egret.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();


private onPostComplete(e:egret.Event):void{
    var request = <egret.HttpRequest>event.currentTarget;
    egret.log("get data : ",request.response);
 } 

private onPostIOError(e:egret.IOErrorEvent):void{

 }

Post方式

var request: egret.HttpRequest;
request = new egret.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"); private onPostComplete(e:egret.Event):void{
var request = <egret.HttpRequest>event.currentTarget;
egret.log("post data : ",request.response);
} private onPostIOError(e:egret.IOErrorEvent):void{ }

五 Post和Get的区别

百度经验 get和post提交方式的区别  http://jingyan.baidu.com/article/d3b74d64abbd6b1f76e60947.html

最新文章

  1. 完美解决AutoCAD2012,AutoCAD2013本身电脑里有NET4.0或以上版本却装不上的问题
  2. C#语言基础——结构体和枚举类型
  3. AX Dynamic 2012 tabletype:TempDB使用
  4. Linux中的TUN/TAP设备
  5. Glut 回调函数小结
  6. hql语句关联查询(select new )
  7. 通过源码学Java基础:BufferedReader和BufferedWriter
  8. json(gson) 转换html标签带来的麻烦
  9. 10.20_wiki
  10. 多目标遗传算法 ------ NSGA-II (部分源码解析) 二进制编码的个体解码操作 decode.c
  11. MySQL 聚簇索引
  12. jQuery创建节点
  13. C1 FlexGrid控件 Editor 冲突问题
  14. Java compiler 并行编译思考
  15. 配置plsql远程连接oracle数据库
  16. JS 比较两个数组是否相等 是否拥有相同元素
  17. 构建oracle12c的Docker镜像
  18. JQUERY-定义-查找
  19. FreeSWITCH媒体转码配置
  20. BZOJ1296: [SCOI2009]粉刷匠 DP

热门文章

  1. xcode armv6 armv7 armv7s arm64
  2. 回顾Spring框架
  3. [转]http://makefiletutorial.com/
  4. 解决ubuntu下安装phpmyadmin访问不了的问题
  5. 378. Kth Smallest Element in a Sorted Matrix
  6. 图片加载完后执行js
  7. java导出excel报错:getOutputStream() has already been called for this response
  8. oc实例变量初始化方法
  9. android首次点击没反应,第二次才反应
  10. Office web app server2013详细的安装和部署