ajax异步调用过程
JS代码:
function example() { var req = getReq(); req.open("GET", "QuerybyActionSample.aspx?name=" + escape(Name), true); req.onreadystatechange = function() { if (req.readyState == 4) { str = req.responseText; showMessage(str); } }; req.send(null); } function getReq() { var oHttpReq = null; if (window.ActiveXObject) {oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");} else if (window.createRequest) {oHttpReq = window.createRequest();} else {oHttpReq = new XMLHttpRequest();} return oHttpReq; }
注:escape()避免了后台获得前台页面值的乱码问题。