Ajax创建

//1 创建对象
var xmlHttp;
function createXMLHttpRequest(){
    if(window.ActiveXObject)
        xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
    else if(widow.XMLHttpRequest)
        xmlHttp = new XMLHttprequest();
}
//2建立请求
    ♠
      var firstName = document.getElementById("firstName").value;
      var url= "9-3.aspx?"+ new Date().getTime();
      xmlHttp.open("GET",url+ "firstName=" + firstName ,ture)//ture表示异步 get方法在提交数据时候在queryString 中发送数据
    ♣
        xmlHttp.open("POST",url);//第4步发送数据时候用xmlHttp.send(firstName)
//3异步对象链接服务器
xmlHttp.onreadystatechange = function(){
    if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
        var responseDiv = document.getElementById("serverResponse");//xmlHttp.responseText服务器的返回并赋值
        responseDiv.innerHTML = decodeURI(xmlHttp.responseText); //解码
}
//4数据发送
xmlHttp.send(null)
   2步骤当为post时候
        xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

posted on 2012-05-16 11:43 youngturk 阅读(227) 评论(0)  编辑  收藏 所属分类: Ajax


只有注册用户登录后才能发表评论。


网站导航:
 
<2012年5月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

导航

统计

公告

this year :
1 jQuery
2 freemarker
3 框架结构
4 口语英语

常用链接

留言簿(6)

随笔分类

随笔档案

文章分类

文章档案

相册

EJB学习

Flex学习

learn English

oracle

spring MVC web service

SQL

Struts

生活保健

解析文件

搜索

最新评论

阅读排行榜

评论排行榜