2011-01-24 11 views
2

私は頭がおかしい人にはおそらく答えがあるという素早い質問があります。 なぜ、この作品xmlhttprequestを変数に格納する方法

<html> 
<head> 
<script type="text/javascript"> 
var xmlhttp; 
function loadXMLDoc(url,cfunc) 
{ 
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=cfunc; 
xmlhttp.open("GET",url,true); 
xmlhttp.send(); 
} 
function myFunction() 
{ 
loadXMLDoc("ajax_info.txt",function() 
    { 
    if (xmlhttp.readyState==4 && xmlhttp.status==200) 
    { 
    document.getElementById("myDiv").innerHTML=xlmhttp.responseText; 
    } 
    }); 
} 
</script> 
</head> 
<body> 

<div id="myDiv"><h2>Let AJAX change this text</h2></div> 
<button type="button" onclick="myFunction()">Change Content</button> 

</body> 
</html> 

を行いますが、私はこの

var txt=xlmhttp.responseText; 
document.getElementById("myDiv").innerHTML=txt; 

は、それはもう動作しません

document.getElementById("myDiv").innerHTML=xlmhttp.responseText; 

聖霊降臨祭を交換する場合、TXTは

を未定義

です

。 xlmhttp.responseTextを文字列に格納する方法、または検索を実行できる変数に格納する方法はありますか?私がそれをやる方法の例を挙げてください。ありがとうございます。)

+2

あなたの変数は 'xlmhttp'ではなく' xmlhttp'と呼ばれますので、どうぞお試しください。 – poke

+0

@ poke-そして、私は[私の答え](http://stackoverflow.com/questions/4775471/how-to-search-through-the-response-of-an-xmlhttprequest/4775773#)でそのオブジェクト名のスペルが間違っているからです4775773)。 ;-) –

+0

男はちょうどそれをチェックしないように地獄のように愚かだが、今私は次回を探すために何を知っている、それは今働く:P – Anders

答えて

2

変数xmlhttpのスペルが間違っている可能性があります。コードに「xlmhttp」があります。

+0

それはまだ動作しません – Sumit

関連する問題