>|
var xmlHttp;
function readPage(url,no){
if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}else{
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}else{
xmlHttp = null;
}
}
xmlHttp.onreadystatechange = checkStatus;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function checkStatus(){
if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
html = xmlHttp.responseText;
alert(html + no); // ★
}
}
|<
上記のコードで、readPage(url,no) で渡した no を、
最後の★印のところで表示するには、どう書けば良いか教えて下さい。
宜しくお願い致します。
「変数のスコープ」の問題な気がします。JavaScriptは門外なので一般的な話をしますが
変数"no"が提示されたコード以外の場所で記述がなければ、readPage()内でのみ有効な
ローカル変数扱いになっているように見えます。
試すとしたら"var xmlHttp;"と同じ位置(下の行とか)に
var no;
と予め宣言を付け足す、とかでしょうか。
ありがとうございました。
http://d.hatena.ne.jp/BigFatCat/20080511/1210521512