发新话题
打印

xml IE的兼容性

xml IE的兼容性

今天做了个提示输入的东东,先做了个实验。
具体做法是
当用户在文本框输入的时候。下面会出现相关的提示。比如输入了a 会提示数据库里其他的东东
如图:
不知道我解释清楚没?
我的程序是这样设计的。
当用户输入的时候,会通过xml调用远程的php程序,程序输出一个xml,被通过responseXML来取回。动态生成div(在一个大div内的小div)。
但问题是:
我的程序在firefox里是很好的实现了,在ie6里就有问题。
经过检查  当我通过responseXML取回xml对象。通过getElementsByTagName("ptt")得到标签为ptt的数组
在firefox里能正确得到数组  在ie6则的不到,因为我alert了一下他的length为0。
我现在是通过responseText 实现了兼容功能(因为时间紧迫)。但我考虑可能是我的php的程序的问题造成的。
求教各位在ajax和php上的达人帮我分析下。
我在这里下发我的数据库的sql文件。和代码压缩包
请朋友们下载后,安装数据库,并在ptt.php里按照您的mysql信息配置正确的数据库链接。后运行下程序。
sql为:
CREATE TABLE `ajax` (
  `nn` varchar(10) NOT NULL default ''
) TYPE=MyISAM;

INSERT INTO `ajax` VALUES ('aa');
INSERT INTO `ajax` VALUES ('bb');
INSERT INTO `ajax` VALUES ('as');
INSERT INTO `ajax` VALUES ('aaer');
INSERT INTO `ajax` VALUES ('afgr');
INSERT INTO `ajax` VALUES ('acdfrt');
附件为程序:
请大家帮我指点迷津,我该如何改
附件: 您所在的用户组无法下载或查看附件
¥¥¥¥¥¥¥
我在天空垂钓,钓一池晶莹剔透的繁星……
$$$$$$$$$$$$

TOP

html程序:
复制内容到剪贴板
代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
    .mouseOut {
    background: #708090;
    color: #FFFAFA;
    }
    .mouseOver {
    background: #FFFAFA;
    color: #000000;
    }
    </style>
<script language="javascript">
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject){
  xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
  xmlHttp= new XMLHttpRequest();
}else{
  alert("false");
}
}
function startrequest(){
var ttv=document.getElementById("inkey").value;
createXMLHttpRequest();
xmlHttp.onreadystatechange=test;
var url="ptt.php?ck="+escape(ttv);
xmlHttp.open("GET",url,true);
//xmlHttp.open("GET","ptt.xml",true);
xmlHttp.send(null);
}
function test(){
if(xmlHttp.readyState==4){
  if(xmlHttp.status==200){
      cleanbefore();
   testmore();
  }
}
}
function cleanbefore(){
var addvv=document.getElementById("add");
var cac=addvv.childNodes.length;
while(cac > 0) {
       addvv.removeChild(addvv.childNodes[0]);
    cac=addvv.childNodes.length;
    }
}
function testmore(){
var xmldoc=xmlHttp.responseXML;
var nott=xmldoc.getElementsByTagName("ptt");
var nolen=nott.length;//alert(nolen);
for(var i=0;i<nolen;i++){
  var vv=nott[i];
  var vll=vv.firstChild.nodeValue;
  ehh(vll);
}
}
function ehh(ttnn){
var dvv=document.createElement("div");
dvv.onmouseout = function() {this.className='mouseOver';};
    dvv.onmouseover = function() {this.className='mouseOut';};
dvv.onclick = function() { onc(this); } ;
var inconn=ttnn;
var pp = document.createTextNode(inconn);
dvv.appendChild(pp);
document.getElementById("add").appendChild(dvv);
}
function onc(nono){
var nova=nono.firstChild.nodeValue;
document.getElementById("inkey").value=nova;
cleanbefore();
}
</script>
</head>
<body>
<input type="text" style="width:150px; text-align:left" id="inkey" onkeyup="startrequest()" />
<div id="add" style="width:150px">
</div>
</body>
</html>
php程序:
复制内容到剪贴板
代码:

<?php
$check=$_GET['ck'];
if($check!=""){
$mycon_c=mysql_connect("localhost","root","cnk8");
$mysdb=mysql_select_db("test");
$str="select nn from ajax where nn like '$check%'";
$fop=fopen("nnd.txt","a+");
$w="---------".date("Y-m-d H:i:s")."---\n$str\n************\n";
fwrite($fop,$w);
$que=mysql_query($str);
header("Content-type: 'text/xml'");
echo "<?xml version='1.0' encoding='UTF-8'?><ptts>";
while($row=mysql_fetch_row($que)){
  echo "<ptt>{$row[0]}</ptt>";
}
echo "</ptts>";
}
?>
¥¥¥¥¥¥¥
我在天空垂钓,钓一池晶莹剔透的繁星……
$$$$$$$$$$$$

TOP

复制内容到剪贴板
代码:
<script language="javascript">
<!--
function makeTip(){

  var nodes = document.getElementsByTagName("div");   
  var len = nodes.length;
  alert(len);
}
//-->
</script>
<input type="text"  size="30" name="keyword" id="keyword" onpropertychange="makeTip();">
<web><domainName>www.sohu.com</domainName><domainName>www.baidu.com</domainName></web>
<div><input type=text><input type=text></div>
如上做了个测试,没什么问题啊

[ 本帖最后由 随风 于 2008-5-29 19:39 编辑 ]
//爱一个人就是在拔通电话时,忽然不知道说什么好,原来只是想听听那熟悉的声音,原来真正想拔动的只是自已心底深处的一根弦

TOP

不好意思啊,晚上回来睡找了
你的那个当然没问题啊 ,页面上本来就有两个div
我的问题在这里
复制内容到剪贴板
代码:

function testmore(){
var xmldoc=xmlHttp.responseXML;
var nott=xmldoc.getElementsByTagName("ptt");
var nolen=nott.length;//alert(nolen);
//var nolen=5;
for(var i=0;i<nolen;i++){
  var vv=nott[i];
  var vll=vv.firstChild.nodeValue;
  ehh(vll);
}
}
在ie里  如果把var nolen=nott.length;//alert(nolen);  后面的//alert(nolen);  变成alert(nolen);  (就是去掉双斜杠.)那么它无法动我的php程序所生成的xml文件里取得  标签为ptt的这个数组的数量,也可以说是没取到数组.在ff里就可以.
不过今天晚上买了本<<Ajax与PHP web开发>> 上面有类似的例子.我大概看了下,貌似对ie和ff分别做了设置.再研究下了.
¥¥¥¥¥¥¥
我在天空垂钓,钓一池晶莹剔透的繁星……
$$$$$$$$$$$$

TOP

发新话题