2008-04-16
AJAX实际应用心得 初级入门篇
最简单的兼容IE和FF的AJAX代码:
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
//alert("IE");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
//alert("FF");
}
}
function getUrlC(){
createXMLHttpRequest();
//alert("setup2");
var url="test2.html";
//alert("setup3");
xmlHttp.open("GET",url,true);
//alert("setup4");
xmlHttp.onreadystatechange=getUrl;
//alert("setup5");
xmlHttp.send(null);
//alert("setup6");
}
function getUrl(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
//alert("hello");
//var contText=document.getElementById("titleD");
//contText.innerHTML=xmlHttp.responseText;
document.getElementById("titleD").innerHTML=xmlHttp.responseText;
}
}
}
</script>
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
//alert("IE");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
//alert("FF");
}
}
function getUrlC(){
createXMLHttpRequest();
//alert("setup2");
var url="test2.html";
//alert("setup3");
xmlHttp.open("GET",url,true);
//alert("setup4");
xmlHttp.onreadystatechange=getUrl;
//alert("setup5");
xmlHttp.send(null);
//alert("setup6");
}
function getUrl(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
//alert("hello");
//var contText=document.getElementById("titleD");
//contText.innerHTML=xmlHttp.responseText;
document.getElementById("titleD").innerHTML=xmlHttp.responseText;
}
}
}
</script>
发表评论
- 浏览: 18236 次
- 性别:

- 来自: 北京

- 详细资料
搜索本博客
我的相册
韩央央
共 72 张
共 72 张
最近加入圈子
最新评论
-
纯CSS打造的导航菜单
似曾相识...
-- by lizhiwei03 -
java中文件操作大全(转)
thanks
-- by 浴盆儿 -
层高度自适应的问题--
这个不叫高度自适应吧!
-- by hellohong -
Java开发者需坚守的十大基 ...
虽然文章说少即是好,但那几个例子够啰嗦的。
-- by yiding_he -
Java开发者需坚守的十大基 ...
泛泛而谈,没价值。如果用来开发手机应用,必死
-- by Azi






评论排行榜