看板 Ajax 關於我們 聯絡資訊
我是只有看一點w3schools.com的說明的ajax新手 我寫了這樣的script == function ajax(method,des,tf,send) { var text var xmlHttp=ajaxFunction(); if(xmlHttp){ xmlHttp.onreadystatechange=function(){ if(xmlHttp.readyState==4){ text=xmlHttp.responseText; //return txt 這裡return不出去,會return sub 而非function } } xmlHttp.open(method,des,tf); xmlHttp.send(send); return text //這裡return會變成未定義 } } function f(){ txt=ajax("GET","test.php",true,null); document.getElementById('mes').innerHTML=txt; } == 我可以確定我的ajaxFunction沒有錯誤 我從firebug可以看到我的responseText確實是我所需要的 但是我的document.getElementById('mes').innerHTML=txt; 這裡面的txt卻是undefined 看起來好像是網路傳輸會lag的關係 請問該怎麼解決這個似乎很基本的問題呢... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.224.40.247
jonce007:xmlHttp.onreadystatechange=function(){ -->CallBack耶~ 03/22 00:19