兼容firefox3,ie,firefox2的xmlhttp请求写法(转载未测)
珙桐565 次
最近安装了firefox3以后突然发现之前写的一些ajax请求无法正常的去获取数据了。于是赶快从网上找解决方法。终于在一个僻静的小角落找到了解决方法。马上写出共享之~积德啊积德~"
//创建xmlhttp。此写法兼容firefox2,firefox3和ie。 function createXMLHTTP() { var xmlhttp = null; if(window.ActiveXObject) { try {xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");} catch(e){try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");} catch(e){}} } else if(window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); if(xmlhttp.overrideMimeType) { xmlhttp.overrideMimeType('text/xml'); } } else {alert("Create XMLHttpRequest object false!");return false;} return xmlhttp; } //调用处写法: var xmlhttp = createXMLHTTP(); xmlhttp.open("GET","your request url",false); xmlhttp.send(null); if(xmlhttp.status == 200) { if(xmlhttp.responseText.length !== 0) { //此判断的内容为以前的回调函数。不明白为啥firefox3就成了这个样子~ }
评论 | 0 条评论