下面这段在IE6可以正常运行,在firefox 和IE7里为什么不行啊 function getNum()
{
var url = "wwwww.aspx";
http.open('GET',url,false);
http.onreadystatechange = function ()
{
if (http.readyState == 4)
{
if (http.Status == 200)
{
document.getElementById("txtBox1").value = http.responseText;
}
}
}
http.send(null);
}
{
var url = "wwwww.aspx";
http.open('GET',url,false);
http.onreadystatechange = function ()
{
if (http.readyState == 4)
{
if (http.Status == 200)
{
document.getElementById("txtBox1").value = http.responseText;
}
}
}
http.send(null);
}
参考如下代码:
function XMLHttpObject(method,url,Syne)
{
var XMLHttp=null;
var o=this;
this.method=method;
this.url=url;
this.Syne=Syne;
this.text="";
this.xmldoc=null;
this.params=null; this.sendData = function()
{
if (window.XMLHttpRequest)
{
XMLHttp = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
with(XMLHttp)
{
open(this.method, this.url, this.Syne);
if(this.method=="post")
{
setRequestHeader("Method", "POST "+this.url+" HTTP/1.1");
setRequestHeader("Content-Type","application/x-www-form-urlencoded");
} else
{
setRequestHeader("Content-Type","text/xml;charset=GBK");
}
onreadystatechange = o.onCallBack;
send(this.params);
}
} this.onCallBack=function()
{
if (XMLHttp.readyState == 4)
{
if (XMLHttp.status == 200)
{
o.text = XMLHttp.responseText;
o.xmldoc=XMLHttp.responseXML;
o.CallBackOK();
} else if(XMLHttp.status == 204)
{
o.CallBackFailed();
} else if(XMLHttp.status == 203)
{
o.CallBackTimeout();
} else
{
o.CallBackFailed();
}
}
} this.CallBackFailed=function(){};
this.CallBackTimeout=function(){};
}
使用下面的 方法获取xmlhttp;
function CreateXMLHttpRequest(){
xmlhttp=false;
if(window.XMLHttpRequest)//Mozilla,Sofari {
xmlhttp=new XMLHttpRequest();
if (xmlhttp.overrideMimeType){
xmlhttp.overrideMimeType('text/xml');
}
}
else if(window.ActiveXObject)//IE
{
try{xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e){
try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
catch(e){}
}
}
}
function getNum()
{
var url = "wwwww.aspx";
http.open('GET',url,false);
http.onreadystatechange = function ()
{
if (http.readyState == 4)
{
if (http.Status == 200)
{
document.getElementById("txtBox1").value = http.responseText;
}
}
};
http.send(null);
}
function httpRequest(reqType,url,asynch)
{
if(window.XMLHttpRequest)
{
//creater object:"request" for Mozillo
request=new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
//for microsoft
request=new ActiveXObject("Msxml2.XMLHTTP");
if(! request)
request=new ActiveXObject("Microsofe.XMLHTTP"); }
if(request)
{
initReq(reqType,url,asynch);
}
}.....参照一下Ajax里的创建XMLHTTP.第一章应该就是讲得这个.估计是那个问题.
很显然,你的代码有问题。
不贴代码?
怎么解决?Status ->status
var http = createXMLHttpRequest();
function createXMLHttpRequest() {
var xmlHttp = false;
if (window.XMLHttpRequest) { // 在非IE浏览器中创建XMLHttpRequest对象
xmlHttp = new XMLHttpRequest();
} else if (window.ActiveXObject) { //通过MS ActiveX创建XMLHttpRequest
try {
// 尝试按新版InternetExplorer方法创建
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e1) { // 创建请求的ActiveX对象失败
try {
// 尝试按老版InternetExplorer方法创建
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
// 不能通过ActiveX创建XMLHttpRequest
}
}
}
return xmlHttp;
} 这是创建的