Ajax局部刷新的步骤(post)提交
1、获取XMLHttpRequest对象,function checkName(){var xhr=null;if(window.XMLHttpRequest){xhr=new XMLHttpRequest();}else{xhr=new ActiveXObject("Microsoft.XMLHttp");}return xhr;}
2、ajax与服务端建立通信连接 xhr.open(请求方式,请求地址,同步或异步);var xhr租涫疼迟=getXhr();var name=$F("username");xhr.open('post','checkName.do',true);xhr.setRequestHeader("content-type","application/x-www-form-urlencoded");
3、xhr.onreadystatechange=function(){if(xhr.readyState==4){var text=xhr.responseText;$("s").innerHTML=text;}}xhr.send("name="+name);
4、<body><form action=""><fieldset><legend>注册</legend>用户:<input id="username" name="name" onblur="checkName_post()"/>
5、<span></span><span id="s"></span><稆糨孝汶;br/>密码:<input type="password" name="psw"><br/><input type="button" name="submit" value="注册"></fieldset></form></body>
6、对于非IE浏览器发送的get请求。我们可以去修改servlet.xml文件添加URIEncoding=“utf-8”; 对于IE浏览器我们可以指定发送请求参数时,使用utf-8编码,只需要给发送的url使用encodeURI(url);