Ajax学习二:异步请求

【1】http://www.ibm.com/developerworks/web/library/wa-ajaxintro2/index.htmljavascript

1. web2.0? 什么是web1.0html

具备彻底不一样请求响应模型传统webjava

  • web1.0 不支持异步请求
  • web2.0 支持异步请求

2. XMLHttpRequest属性和方法web

  • open(): Sets up a new request to a server.
  • send(): Sends a request to a server.
  • abort(): Bails out of the current request.
  • readyState: Provides the current HTML ready state.
  • responseText: The text that the server sends back to respond to a request.

static javascript: 代码没有放在一个方法或者函数体内,在用户与页面交互以前运行ajax


能够将建立XMLHttpRequest的代码放在函数里面,可是会有问题:若是你是在用户填入第14个文本框时执行Ajax代码,而后回复一个浏览器不支持的错误给用户,会致使一个很是差的体验,由于用户已经在这个页面花掉了10分钟的时间。因此仍是建议使用static的代码。跨域

 


 

ajax sandbox:  【2】http://www.cnblogs.com/ComeOn/archive/2008/01/30/1058942.html浏览器

AJAX中的沙箱安全模型主要指的是跨域脚本调用的问题。好比咱们存在在www.cnblogs.com中的脚本若是想访问www.163.com 脚本是违反沙箱安全模型的。结果确定会出错。安全


 

 

http ready state异步

  • 0: The request is uninitialized (before you've called open()).
  • 1: The request is set up, but hasn't been sent (before you've called send()).
  • 2: The request was sent and is being processed (you can usually get content headers from the response at this point).
  • 3: The request is being processed; often some partial data is available from the response, but the server hasn't finished with its response.
  • 4: The response is complete; you can get the server's response and use it.
相关文章
相关标签/搜索