初始化對象并發出xmlhttprequest請求
var xmlhttp; if(window.xmlhttprequest){ xmlhttp = new xmlhttprequest(); }else
if(window.activexobject){ xmlhttp = new activexobject(“mircosoft.xmlhttp”);
}
注:有些版本的mozilla浏覽器處理伺服器傳回的未包含xml
mime-type頭部資訊的内容時會出錯,是以,要確定傳回的内容包含text/xml,需加入:
xmlhttp.overridemimetype(“text/xml”);
ajax開發步驟
responsetext 将傳回的資訊當字元串使用
responsexml 将傳回的資訊當xml文檔使用,需用dom進行解析處理
使用 dom(document object model)進行動态顯示及互動;
使用 xml 和 xslt 進行資料交換及相關操作;
使用 xmlhttprequest 進行異步資料查詢、檢索;
ajax 使用 javascript 将所有的東西綁定在一起