PHP & JavaScript Room :: 設置サンプル

実行結果

ソース

<script type="text/javascript">
function testXmlHttpRequestObj(xmlURL){
    /* キャンセル用FLG */
    var errFLG=true;
    /* XMLHttpRequestオブジェクト作成 */
    var xmlhttp=false;
    if(typeof ActiveXObject!="undefined"){ /* IE5, IE6 */
        try {
            xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); /* MSXML3 */
        }
        catch(e){
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); /* MSXML2 */
        }
    }
    if(!xmlhttp && typeof XMLHttpRequest!="undefined"){
        xmlhttp=new XMLHttpRequest(); /* Firefox, Safari, IE7 */
    }
    if(!xmlhttp){
        alert("XMLHttpRequest非対応ブラウザ");
        return false;
    }
    /* レスポンスデータ処理 */
    xmlhttp.onreadystatechange=function(){
        if(xmlhttp.readyState==4 && xmlhttp.status==200){
            document.getElementById("res").innerHTML="データ受信完了";
            document.getElementById("resXmlHttpRequestObj").innerHTML="<textarea style='width:450px; height:200px;'>"+xmlhttp.responseText+"</textarea>";
        }
    }
    /* HTTPリクエスト実行 */
    xmlhttp.open("GET",xmlURL,true);
    if(xmlhttp.readyState==1 && errFLG==true){
        /* ★リクエストをキャンセル(readyState=0の処理状態に戻す)*/
        xmlhttp.abort();
        document.getElementById("res").innerHTML="リクエストをキャンセルしました";
    }else{
        /* sendメソッド実行 */
        xmlhttp.send(null);
    }
}
window.onload=function(){
    /* ページ読み込み完了時に実行 */
    testXmlHttpRequestObj("./xml/ranking.xml");
}
</script>
<div id="res"></div>
<div id="resXmlHttpRequestObj"></div>

polarized women