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

実行結果

ソース

<script type="text/javascript">
function testXmlHttpRequestObj(xmlURL){
    /* 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;
    }

    /* レスポンスデータ処理 */

    /* ▼いずれかを使用 */
    /**************************** 例1:匿名関数 */
//    xmlhttp.onreadystatechange=function(){
//        if(xmlhttp.readyState==4 && xmlhttp.status==200){
//            /* XMLデータ取得 */
//            document.getElementById("resXmlHttpRequestObj").innerHTML=xmlhttp.responseXML;
//        }
//    }

    /**************************** 例2:関数を代入 */
    xmlhttp.onreadystatechange=func;
    function func(){
        if(xmlhttp.readyState==4 && xmlhttp.status==200){
            /* XMLデータ取得 */
            document.getElementById("resXmlHttpRequestObj").innerHTML=xmlhttp.responseXML;
        }
    }
    /* ▲いずれかを使用 */

    /* HTTPリクエスト初期化+HTTPメソッドおよびリクエスト先URLの設定 */
    xmlhttp.open("GET",xmlURL,true);
    /* リクエスト送信 */
    xmlhttp.send(null);
}
window.onload=function(){
    /* ページ読み込み完了時に実行 */
    testXmlHttpRequestObj("./xml/ranking.xml");
}
</script>
<div id="resXmlHttpRequestObj"></div>

polarized women