当前位置:编程学习 > JS >>

AJAX 兼容问题 求解决 在火狐下正常显示 IE下AJAX返回结果输出不到指定位置.代码如下:

前台页面:
<script type="text/javascript">
function createRequest(){
    var request;
    if(window.XMLHttpRequest){ // For Mozilla, Safari, ...
        request = new XMLHttpRequest();
    } else if(window.ActiveXObject){ // For Internet Explorer
   try {
   request = new ActiveXObject("Msxml2.XMLHTTP");
   } catch (e) {
     try {
    request = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (e) {}
   }
    }
    return request;
}
function getcity(ctid,tid){
    var ajax=createRequest();
    var url = "aja.php?cid="+tid+"&ccc="+ctid;
 alert(url);
 //location=url;
    ajax.open("GET",url,true);
    ajax.onreadystatechange = function () {
        if (ajax.readyState == 4 && ajax.status==200) {
   if(window.XMLHttpRequest){
   document.getElementById(ctid).innerHTML=ajax.responseText;}
   else
   {
   document.getElementById(ctid).outerHTML=ajax.responseText;}
   document.getElementById(ctid).style.display='inline';
   if(ctid=="typeidj")
   {
    document.getElementById("typeidh").style.display='none';
    document.getElementById("typeid").style.display='none';
   }else if(ctid=="typeidh")
   {
    document.getElementById("typeid").style.display='none';
   }
   //alert(ajax.responseText);
        }
    }
    ajax.send(null);
}
</script>
<select name='typeidk' style='width:200' onchange=\"getcity('typeidj',document.form1.typeidk.value)\">
<option value='0' selected>所有栏目...</option>
<option value='1‘>aaa</option></select>
 <select name='typeidj' style='width:200; display:none' id="typeidj" onchange="getcity('typeidh',document.form1.typeidj.value)">
</select>     
----php处理页

<?php
require_once(dirname(__FILE__)."/config.php");
require_once(DEDEINC."/typelink.class.php");
$cid=$_GET['cid'];
$pp=$_GET['ccc'];
$tl = new TypeLink($cid);
$tl->dsql->SetQuery("SELECT * FROM `dede_arctype` where reid=$cid order by sortrank asc");
$tl->dsql->Execute();
if($pp=="typeidj") {
//echo"<select name='typeidj' style='width:150px;' id='typeidj' onchange=\"getcity('typeidh',document.form1.typeidj.value)\">";
echo" <option value='-1' selected='selected'>所有区域...</option>";
while($row = $dsql->GetObject())
{
   echo "<option value='".$row->id."'>".$row->typename."</option>\r\n";
}
//echo "</select>";
}else if($pp=="typeidh") {
//echo"<select name='typeidh' style='width:150px;' id='typeidh' onchange='getcity('typeid',document.form1.typeidh.value)'>";
echo" <option value='-2' selected='selected'>所有平台...</option>";
while($row = $dsql->GetObject())
{
   echo "<option value='".$row->id."'>".$row->typename."</option>\r\n";
}
//echo "</select>";
}else if($pp=="typeid") {
//echo"<select name='typeid' style='width:150px;' id='typeid'>";
echo" <option value='-3' selected='selected'>所有栏目...</option>";
while($row = $dsql->GetObject())
{
   echo "<option value='".$row->id."'>".$row->typename."</option>\r\n";
}
//echo "</select>";
}
?>

追问:解决了 兼容 不过 又出新问题了 不过 谢谢你了!

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,