Home > 備忘録 > 言語関連 > javascript に関すること > XMLHttpRequest( 30 )
function CreateXMLHttpRequest(){ // XMLHttpRequest オブジェクトを作成
if(XMLHttpRequest){
return new XMLHttpRequest();
}else{
try{
return new ActiveXObject("MSXML2.XMLHTTP.6.0");
}catch(e){}
try{
return new ActiveXObject("MSXML2.XMLHTTP.3.0");
}catch(e){}
try{
return new ActiveXObject("MSXML2.XMLHTTP");
}catch(e){}
}
return null;
}function ReadData(url){
var xhr = CreateXMLHttpRequest(); // XMLHttpRequest オブジェクトを作成
xhr.open("POST",url,false); // POST メソッドで接続先 URL を指定(true:非同期 / false:同期)
xhr.onreadystatechange = function (evnt){ //コールバック
if (xhr.readyState==4&&xhr.status==200) alert(xhr.responseText); //読み込んだデータを表示
};
xhr.send(null); // 受信を開始する
}function ReadData(url){
var xhr = CreateXMLHttpRequest(); // XMLHttpRequest オブジェクトを作成
xhr.open("POST",url,false); // POST メソッドで接続先 URL を指定(true:非同期 / false:同期)
xhr.send(null); // 受信を開始する
if(xhr.readyState==4 && xhr.status==200){
alert(xhr.responseText); //読み込んだデータを表示
};
}