Ajax局部刷新的步骤(post)提交

2025-04-24 08:12:35

1、获取XMLHttpRequest对象,function checkName(){var xhr=null;if(window.XMLHttpRequest){xhr=new XMLHttpRequest();}else{xhr=new ActiveXObject("Microsoft.XMLHttp");}return xhr;}

Ajax局部刷新的步骤(post)提交

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");

Ajax局部刷新的步骤(post)提交

3、xhr.onreadystatechange=function(){if(xhr.readyState==4){var text=xhr.responseText;$("s").innerHTML=text;}}xhr.send("name="+name);

Ajax局部刷新的步骤(post)提交

4、<body><form action=""><fieldset><legend>注册</legend>用户:<input id="username" name="name" onblur="checkName_post()"/>

Ajax局部刷新的步骤(post)提交

5、<span></span><span id="s"></span><稆糨孝汶;br/>密码:<input type="password" name="psw"><br/><input type="button" name="submit" value="注册"></fieldset></form></body>

Ajax局部刷新的步骤(post)提交

6、对于非IE浏览器发送的get请求。我们可以去修改servlet.xml文件添加URIEncoding=“utf-8”; 对于IE浏览器我们可以指定发送请求参数时,使用utf-8编码,只需要给发送的url使用encodeURI(url);

Ajax局部刷新的步骤(post)提交
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢