getElementsByTagName問題求解

來源:互聯網
上載者:User

聊天室(您正在和聊天)






execute_dml($sql);}//擷取資訊,並把資料群組裝好返回給用戶端(聊天室)function getMessage($getter,$sender){$sql="select * from message where getter='$getter' and sender='$sender' and isGet=0";$sqlHelper=new SqlHelper();$array=$sqlHelper->execute_dql2($sql);$messageInfo="";for($i=0;$i< count($array);$i++){$row=$array[$i];$messageInfo.="{$row['id']}{$row['sender']}{$row['getter']}{$row['content']}{$row['sendTime']}";}$messageInfo.="";file_put_contents("d:/test.txt",$messageInfo."\r\n",FILE_APPEND);$sqlHelper->close_connect();return $messageInfo;}}





getMessage($getter,$sender);//file_put_contents("d:/test.txt","news--".$mesList."\r\n",FILE_APPEND);echo $mesList;?>




為什麼在第一段函數getMessage()中
var cons=mesRes.getElementsByTagName("con");
alert時為0.資料庫中有添加了記錄
我看的是韓順平的php視頻。
求大神搭救


回複討論(解決方案)

在IE中getElementsByName()是根據ID來取的,但在其他瀏覽器中,是正常按name屬性來取的,因此如果你的代碼運行在非IE瀏覽器上,就會出現取不到值的現象

抱歉,沒留意你寫的是 getElementsByTagName() 你應該改成 getElementById()
var cons=mesRes.getElementById("con");
var sendTimes=mesRes.getElementById("sendTime");
另外你還有不少低級的錯誤
$('mycons').value+="對說:"+cons[i].childNodes[0].nodeValue+" "+sendTimes[i].childNodes[0].nodeValue;
php代碼是不會被用戶端瀏覽器執行的,而且你得到的 cons, sendTimes 都只是一個DOM對象,而不是一個結果集

抱歉,沒留意你寫的是 getElementsByTagName() 你應該改成 getElementById()
var cons=mesRes.getElementById("con");
var sendTimes=mesRes.getElementById("sendTime");
另外你還有不少低級的錯誤
$('mycons').value+="

很感謝你的指導。新手呢,我今天知道問題出在哪了

 header("conntent-type:text/xml;charset=utf-8");    header("Cache-Control:no-cache");

這裡是content-type打多了個n
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.