2012-08-06 32 views
0

我只是試圖讀取div內的html文件,現在它不工作,因此我試圖讀取一個簡單的文本文件名爲a.txt,該文本文件包含3行「asdasdas 「類似的東西。簡單的ajax錯誤驅使我瘋狂

它只是將無法正常工作,該功能被按下一個段落標記後調用,這裏是代碼:

functionNew() 
{  
    var xmlhttp; 
    if (window.XMLHttpRequest) 
     {// code for IE7+, Firefox, Chrome, Opera, Safari 
     xmlhttp=new XMLHttpRequest(); 
     } 
    else 
     {// code for IE6, IE5 
     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
     } 

    xmlhttp.onreadystatechange=function() 
     { 
     if (xmlhttp.readyState==4 && xmlhttp.status==200) 
     { 
      document.getElementById("divfull").innerHTML = xmlhttp.responseText; 
     } 
     } 
    xmlhttp.open("GET","a.txt",true); 
    xmlhttp.send(null); 

} 

任何想法,爲什麼它不工作?

+0

嘗試把完整路徑的文件,例如工作http://thing.com/a.txt – 2012-08-06 18:03:54

+0

這是我的電腦上.. 是我與螢火蟲得到的錯誤是誤了Syntex OK – user1104615 2012-08-06 18:04:36

+0

,該行被指向它? – 2012-08-06 18:06:32

回答

0

代碼似乎是正確的,但嘗試調用

xmlhttp.open("GET","a.txt",true); 

xmlhttp.onreadystatechange=function() 

嘗試,讓我們知道,如果它爲您