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.
相關文章
相關標籤/搜索