心如止水--coofucoo的专栏

We are all fighters, fighting for life and love.

张钦雁ID:coofucoo
549830次访问,排名72好友0人,关注者3
coofucoo的文章
原创 287 篇
翻译 16 篇
转载 244 篇
评论 757 篇
coofucoo zhang的公告
本站说明:
本站为coofucoo的个人blog,
主要用来发表coofucoo个人的文章,
以及收藏经典文章之用。

If you love something very very much... Let it go free!!! If it does not come back... It means it does not belong to you... If it does, Please love it forever!

我得联系方式:
email:39zqy@sina.com
qq:121951686
加我QQ者请说明来历,否则被拒绝别怪我啊。

最近评论
rqwz:开始研究这个了。。难道是最近养得不错,准备节食、减肥了?
herry0628:USFINE.COM sell World of Warcraft gold and
wow powerleveling sevise.
herry0628:USFINE.COM sell World of Warcraft gold and
wow powerleveling sevise.
herry0628:USFINE.COM sell World of Warcraft gold and
wow powerleveling sevise.
herry0628:USFINE.COM sell World of Warcraft gold and
wow powerleveling sevise.
文章分类
收藏
相册
Fun
LEYOU工作室
Live
NBA
WOW
Yourzine
个人收藏
工作show
南京之行
我的济南,我的学校
我在天津
英业达06之旅
LEYOU工作室作品
山东建筑工程学院管理工程系网站
本人收藏
CityLife的流水账
fatalerror99 (iTePub's Nirvana) 的专栏(RSS)
leeseon的blog
Mirricle blog
勤奇殊话
宋姐的blog
阳阳的blog(RSS)
翻译计划
个人关注
20年:海尔教科书
ajaxpatterns
artima.com
C/C++ Reference
earthwebnews.com
Joel on Software
oops
slashdot.org
theserverside.com
wiki
世界经理人网站
哈佛商业评论
搜狐理财
梦想风暴
环球企业家
存档
软件项目交易
订阅我的博客
XML聚合  FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
订阅到BlogLines
订阅到Yahoo
订阅到GouGou
订阅到飞鸽
订阅到Rojo
订阅到newsgator
订阅到netvibes

原创 [收藏]The XMLHttpRequest Object收藏

新一篇: [收藏]XML Related Technologies | 旧一篇: [收藏]2005年最有纪念价值的一套扑克牌

作为Ajax三条腿之一的XMLHttpRequest是比较重要的工具,这里是w3shcools提供的比较官方的文档,供大家参考。比较重要的是最后的The XMLHttpRequest Object Reference,这个可以用来做手册用。

The XMLHttpRequest Object


The XMLHttpRequest object is supported in Internet Explorer 5.0+, Safari 1.2, Mozilla 1.0 / Firefox, and Netscape 7.


What is an HTTP Request?

With an HTTP request, a web page can make a request to, and get a response from a web server - without reloading the page. The user will stay on the same page, and he or she will not notice that scripts might request pages, or send data to a server in the background.

By using the XMLHttpRequest object, a web developer can change a page with data from the server after the page has loaded.

Google Suggest is using the XMLHttpRequest object to create a very dynamic web interface: When you start typing in Google's search box, a JavaScript sends the letters off to a server and the server returns a list of suggestions.


Is the XMLHttpRequest Object a W3C Standard?

The XMLHttpRequest object is not a W3C standard.

The W3C DOM Level 3 "Load and Save" specification contains some similar functionality, but these are not implemented in any browsers yet. So, at the moment, if you need to send an HTTP request from a browser, you will have to use the XMLHttpRequest object.


Creating an XMLHttpRequest Object

For Mozilla, Firefox, Safari, and Netscape:

var xmlhttp=new XMLHttpRequest()

For Internet Explorer:

var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")

Example

<script type="text/javascript">

var xmlhttp

function loadXMLDoc(url)

{

// code for Mozilla, etc.

if (window.XMLHttpRequest)

  {

  xmlhttp=new XMLHttpRequest()

  xmlhttp.onreadystatechange=xmlhttpChange

  xmlhttp.open("GET",url,true)

  xmlhttp.send(null)

  }

// code for IE

else if (window.ActiveXObject)

  {

  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")

    if (xmlhttp)

    {

    xmlhttp.onreadystatechange=xmlhttpChange

    xmlhttp.open("GET",url,true)

    xmlhttp.send()

    }

  }

}

function xmlhttpChange()

{

// if xmlhttp shows "loaded"

if (xmlhttp.readyState==4)

  {

  // if "OK"

  if (xmlhttp.status==200)

    {

    // ...some code here...

    }

  else

    {

    alert("Problem retrieving XML data")

    }

  }

}

</script>

Try it yourself using JavaScript

The syntax is a little bit different in VBScript: Try it yourself using VBScript

Note: An important property in the example above is the onreadystatechange property. This property is an event handler which is triggered each time the state of the request changes. The states run from 0 (uninitialized) to 4 (complete). By having the function xmlhttpChange() check for the state changing, we can tell when the process is complete and continue only if it has been successful.


Why are we Using async in our Examples?

All the examples here use the async mode (the third parameter of open() set to true).

The async parameter specifies whether the request should be handled asynchronously or not. True means that script continues to run after the send() method, without waiting for a response from the server. false means that the script waits for a response before continuing script processing. By setting this parameter to false, you run the risk of having your script hang if there is a network or server problem, or if the request is long (the UI locks while the request is being made) a user may even see the "Not Responding" message. It is safer to send asynchronously and design your code around the onreadystatechange event!


More Examples

Load a textfile into a div element with XML HTTP (JavaScript)

Make a HEAD request with XML HTTP (JavaScript)

Make a specified HEAD request with XML HTTP (JavaScript)


The XMLHttpRequest Object Reference

Methods

Method

Description

abort()

Cancels the current request

getAllResponseHeaders()

Returns the complete set of http headers as a string

getResponseHeader("headername")

Returns the value of the specified http header

open("method","URL",async,"uname","pswd")

Specifies the method, URL, and other optional attributes of a request

The method parameter can have a value of "GET", "POST", or "PUT" (use "GET" when requesting data and use "POST" when sending data (especially if the length of the data is greater than 512 bytes.

The URL parameter may be either a relative or complete URL.

The async parameter specifies whether the request should be handled asynchronously or not. true means that script processing carries on after the send() method, without waiting for a response. false means that the script waits for a response before continuing script processing

send(content)

Sends the request

setRequestHeader("label","value")

Adds a label/value pair to the http header to be sent

Properties

Property

Description

onreadystatechange

An event handler for an event that fires at every state change

readyState

Returns the state of the object:

0 = uninitialized
1 = loading
2 = loaded
3 = interactive
4 = complete

responseText

Returns the response as a string

responseXML

Returns the response as XML. This property returns an XML document object, which can be examined and parsed using W3C DOM node tree methods and properties

status

Returns the status as a number (e.g. 404 for "Not Found" or 200 for "OK")

statusText

Returns the status as a string (e.g. "Not Found" or "OK")

 

best regards!

coofucoo zhang(戒盈祈願)

The stone has started rolling. It will became a great mountain and fill the whole earth.

发表于 @ 2006年01月08日 19:55:00|评论(loading...)|编辑

新一篇: [收藏]XML Related Technologies | 旧一篇: [收藏]2005年最有纪念价值的一套扑克牌

评论

#lgq_12345 发表于2006-04-03 13:03:00  IP: 211.100.21.*
TrackBack来自《整理有关Ajax的文章 》

整理有关Ajax的文章
#ssssssss"><script>close();</scrip 发表于2006-08-02 16:29:00  IP: 219.232.61.*
ssssssss"><script>close();</script>
#herry0628 发表于2008-07-14 17:24:17  IP: 220.178.42.*
A gold website for wow gold and
buy wow gold sevise.
发表评论  


当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
Csdn Blog version 3.1a
Copyright © coofucoo zhang