传统ajax Code 复制代码 代码如下: <br>var xmlHttp; <br>function createXMLHttpRequest(){ <br>if(window.ActiveXObject) <br>xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); <br>else if(window.XMLHttpRequest) <br>xmlHttp = new XMLHttpRequest(); <br>} <br>function startRequest(){ <br>createXMLHttpRequest(); <br>xmlHttp.open("GET","14-1.aspx",true); <br>xmlHttp.onreadystatechange = function(){ <br>if(xmlHttp.readyState == 4 && xmlHttp.status == 200) <br>document.getElementById("target").innerHTML = xmlHttp.responseText; <br>} <br>xmlHttp.send(null); <br>} <br> JQuery方法 Code 复制代码 代码如下: <br>function startRequest(){ <br>$("#target").load("14-1.aspx"); <br>} <br> get and post Code 复制代码 代码如下: GET VS. POST <br>function createQueryString(){ <br>var firstName = encodeURI($("#firstName").val()); <br>var birthday = encodeURI($("#birthday").val()); <br>//组合成对象的形式 <br>var queryString = {firstName:firstName,birthday:birthday}; <br>return queryString; <br>} <br>function doRequestUsingGET(){ <br>$.get("14-5.aspx",createQueryString(), <br>//发送GET请求 <br>function(data){ <br>$("#serverResponse").html(decodeURI(data)); <br>} <br>); <br>} <br>function doRequestUsingPOST(){ <br>$.post("14-5.aspx",createQueryString(), <br>//发送POST请求 <br>function(data){ <br>$("#serverResponse").html(decodeURI(data)); <br>} <br>); <br>} <br> 输入姓名和生日