IE中不用ActiveX的情况下实现AJAX

 IE中不用ActiveX的情况下实现AJAX
| |
[晴 2006/04/05 10:42 | by chirs@zhoujin.com ]
发现这篇文章:
http://verens.com/archives...

提供以下代码:
/*
/*
coded by Kae - http://verens.com/
use this code as you wish, but retain this notice
*/

function XMLHttpRequest() {
var i=0;
var url='';
var responseText='';
this.onreadystatechange=function(){
return false;
}

this.open=function(method,url){
//TODO: POST methods
this.i=++kXHR_instances; // id number of this request
this.url=url;
var iframe=document.createElement('');
document.body.appendChild(iframe);
}

this.send=function(postdata){
//TODO: use the postdata
var el=document.getElementById('kXHR_iframe_'+this.i);
el.src=this.url;
kXHR_objs[this.i]=this;
setTimeout('XMLHttpRequest_checkState('+this.i+')',500);
}

return true;
}

function XMLHttpRequest_checkState(inst)
{
var el=document.getElementById('kXHR_iframe_'+inst);
if(el.readyState=='complete'){
var responseText=window.frames['kXHR_iframe_'+inst].document.body.childNodes[0].data;
kXHR_objs[inst].responseText=responseText;
kXHR_objs[inst].readyState=4;
kXHR_objs[inst].status=200;
kXHR_objs[inst].onreadystatechange();
el.parentNode.removeChild(el);
}else{
setTimeout('XMLHttpRequest_checkState('+inst+')',500);
}
}

var kXHR_instances=0;
var kXHR_objs=[];



通过创建iFrame来提交数据,代替用ActiveX组件创建XmlHttp对象。
这样的实现方法,还真想不到。
阅读更多
个人分类: WEB2.0 +AJAX
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭