Chair's blog
2009年1月14日 星期三
AJAX 基本步驟
//██████████████ Ajax ██████████████ var http_request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { //try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); //} catch (e) {} } } if (!http_request) { alert('Giving up :( Cannot create an XMLHTTP instance'); return false; } http_request.onreadystatechange = function() { alertContents(http_request); }; http_request.open('GET','取得網頁內容.php', true); http_request.setRequestHeader("If-Modified-Since","0");//清除 IE cache http_request.send(null); function alertContents(http_request) { if (http_request.readyState == 4) { if (http_request.status == 200) { var html= http_request.responseText; document.getElementById("view1").innerHTML=html; } else { alert('There was a problem with the request.'); } } } //██████████████ END ██████████████
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
查看行動版
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言