ie8运行上面AJAX代码无法获取执行状态
functioncreatexmlhttp(){varxmlhttpobj=false;if(window.XMLHttpRequest){xmlhttpobj=newX...
function createxmlhttp(){
var xmlhttpobj = false;
if(window.XMLHttpRequest){
xmlhttpobj=new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
try{
//Firefox, Opera 8.0+, Safari
xmlhttpobj = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
//Internet Explorer
try{
xmlhttpobj = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
xmlhttpobj = false;
}
}
}
return xmlhttpobj;
}
function getsubcategory(bigclassid){
if(bigclassid==0){
document.getElementById("subclass").innerHTML="<select name='smallclassid'><option value='0' selected>选择二级分类</option></select>";
return;
};
var xmlhttpobj = createxmlhttp();
if(xmlhttpobj){//如果创建对象xmlhttpobj成功
xmlhttpobj.open('get',"../getsubcategory.asp?bigclassid="+bigclassid+"&number="+Math.random(),true);//get方法 加个随机数。
xmlhttpobj.send(null);
xmlhttpobj.onreadystatechange=function(){//客户端监控函数
//alert(xmlhttpobj.readystate);
if(xmlhttpobj.readystate==4){//服务器处理请求完成
if(xmlhttpobj.status==200){
//alert('ok');
var html = xmlhttpobj.responseText;//获得返回值
document.getElementById("subclass").innerHTML=html;
}else{
document.getElementById("subclass").innerHTML="对不起,您请求的页面有问题...";
}
}else{
document.getElementById("subclass").innerHTML="加载中,请梢候...";//服务器处理中
}
}
}
} 展开
var xmlhttpobj = false;
if(window.XMLHttpRequest){
xmlhttpobj=new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
try{
//Firefox, Opera 8.0+, Safari
xmlhttpobj = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
//Internet Explorer
try{
xmlhttpobj = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
xmlhttpobj = false;
}
}
}
return xmlhttpobj;
}
function getsubcategory(bigclassid){
if(bigclassid==0){
document.getElementById("subclass").innerHTML="<select name='smallclassid'><option value='0' selected>选择二级分类</option></select>";
return;
};
var xmlhttpobj = createxmlhttp();
if(xmlhttpobj){//如果创建对象xmlhttpobj成功
xmlhttpobj.open('get',"../getsubcategory.asp?bigclassid="+bigclassid+"&number="+Math.random(),true);//get方法 加个随机数。
xmlhttpobj.send(null);
xmlhttpobj.onreadystatechange=function(){//客户端监控函数
//alert(xmlhttpobj.readystate);
if(xmlhttpobj.readystate==4){//服务器处理请求完成
if(xmlhttpobj.status==200){
//alert('ok');
var html = xmlhttpobj.responseText;//获得返回值
document.getElementById("subclass").innerHTML=html;
}else{
document.getElementById("subclass").innerHTML="对不起,您请求的页面有问题...";
}
}else{
document.getElementById("subclass").innerHTML="加载中,请梢候...";//服务器处理中
}
}
}
} 展开
2个回答
展开全部
createXMLHttpRequest = function(){
var request;
if(window.XMLHttpRequest){
request = new XMLHttpRequest();
}else{
var signatures = ["MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0",
"MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP.2.0",
"Microsoft.XMLHTTP"];
for(var i=0;i<signatures.length;i++){
try{
request = new ActiveXObject(signatures[i]);
}catch(error){
}
}
throw new Error("MSXML is not installed on your system.");
}
return request;
}
用这个函数创建httprequest对象试试
var request;
if(window.XMLHttpRequest){
request = new XMLHttpRequest();
}else{
var signatures = ["MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0",
"MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP.2.0",
"Microsoft.XMLHTTP"];
for(var i=0;i<signatures.length;i++){
try{
request = new ActiveXObject(signatures[i]);
}catch(error){
}
}
throw new Error("MSXML is not installed on your system.");
}
return request;
}
用这个函数创建httprequest对象试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询