[已解決] 關於DOM節點 Undifine

看板Ajax作者 (小雷)時間15年前 (2010/09/03 12:35), 編輯推噓4(408)
留言12則, 2人參與, 最新討論串1/3 (看更多)
以下是我ajax送出的要求 <?php header( "Cache-Control: no-cache, must-revalidate" ); header( "Pragma: no-cache" ); echo '<?xml version="1.0" encoding="big5"?>'; echo "<response>"; $uFlag= 0; $message=""; if(isset($_GET["m_username"])){ require_once("../include/selectmemberdata.php"); $query_RecFindUser = "SELECT `m_username` FROM `memberdata` WHERE `m_username`='".$_GET["m_username"]."'"; $RecFindUser = mysql_query($query_RecFindUser); if(mysql_num_rows($RecFindUser)>0){ $message +="已經有人註冊過"; } else{ $message += "可以註冊"; $uFlag = 1; } } echo '<passed>'.$uFlag.'</passed>'; echo '<message>'.$message.'</message>'; echo "</response>"; ?> 下面是js接收回傳值處理的函數 function alertContents() { if (http_request.readyState == 4) { if (http_request.status == 200) { var xmldoc = http_request.responseXML; var mes = xmldoc.getElementsByTagName("message")[0].firstChild.data; 這邊顯示undifine } else { alert('There was a problem with the request.'+ http_request.status); } } } 爬文沒找到一些解決辦法 上來請問一下前輩 -- 活在我不懂的道理 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 203.64.102.55 ※ 編輯: rex921 來自: 203.64.102.55 (09/03 13:23)

09/03 20:17, , 1F
看看你的XMLHttpRequest方法封裝 有沒有下async:false
09/03 20:17, 1F

09/03 20:17, , 2F
這問題我被搞過@@'
09/03 20:17, 2F
不好意思..我剛接觸ajax,可否麻煩你詳細說明一下嗎?還是我要在補充哪些code給你︿︿ ※ 編輯: rex921 來自: 203.64.102.55 (09/03 20:24)

09/03 20:30, , 3F
恩...[還有一個情況是換行也會被當成一個節點
09/03 20:30, 3F

09/03 20:31, , 4F
對了 如果只是要傳遞一行訊息可以改用json xml對這功能
09/03 20:31, 4F

09/03 20:31, , 5F
算太肥大
09/03 20:31, 5F
我目前要做的功能是註冊帳號的驗證是否重複 我的表單有一顆按鈕預設disabled想說用response來判斷決定是否enabled 可是卡在無法解析xml 囧....我再試試看 ※ 編輯: rex921 來自: 203.64.102.55 (09/03 20:35)

09/03 20:38, , 6F
json會比較適合你的用途
09/03 20:38, 6F
嗯 那我得去爬爬json了 謝謝 ※ 編輯: rex921 來自: 203.64.102.55 (09/03 20:39)

09/03 20:39, , 7F
php好像有jsonencode()函式可以用
09/03 20:39, 7F
謝謝 還在試..不知道怎麼解析...繼續爬文@@ ※ 編輯: rex921 來自: 203.64.102.55 (09/03 20:55)

09/03 20:56, , 9F
解析喔...json還沒試過耶 我也順便來學好了
09/03 20:56, 9F

09/03 21:45, , 10F
阿 這麼快 我還卡著= = 有哪些重點 可以提示一下嗎@@ ※ 編輯: rex921 來自: 218.173.160.131 (09/03 22:01) ※ 編輯: rex921 來自: 218.173.160.131 (09/03 22:04) ※ 編輯: rex921 來自: 203.64.102.55 (09/09 19:45) ※ 編輯: rex921 來自: 203.64.102.55 (09/09 19:45)

09/10 16:35, , 11F
先把 http_request.responseXML 換成 responseText
09/10 16:35, 11F

09/10 16:36, , 12F
把傳回來的內容alert出來看看 是不是正確的xml
09/10 16:36, 12F
文章代碼(AID): #1CW7iLz8 (Ajax)
文章代碼(AID): #1CW7iLz8 (Ajax)