js 代码
- if (window.ActiveXObject && !window.XMLHttpRequest) {
- window.XMLHttpRequest=function() {
- return new ActiveXObject((navigator.userAgent.toLowerCase().indexOf('msie 5') != -1) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP');
- };
- }
- function exeRequest(url,handle,v){
- xmlHttp=new XMLHttpRequest();
- xmlHttp.onreadystatechange=function (){
- if(xmlHttp.readyState==4){
- if(xmlHttp.status==200){
- var v=xmlHttp.responseText;
- if(v=="xmlerr"){
- alert("数据传输错误,请刷新页面重试");
- return;
- }
- handle(v);
- }
- }
- };
- xmlHttp.open("post",url);
- xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- xmlHttp.send(v);
- }
- //example: arg0是发送的参数以key=value形式发送,或者以xml格式发送
- function doAjaxReq(arg0){
- var url="";//发送的url,不能垮域请求
- exeRequest(url,handelDoAjaxReq,arg0);
- }
- //方法回调,进行响应处理
- function handelDoAjaxReq(v){
- if(v==1){
- alert("请求成功");
- }
- }