jQueryなしのAjax
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40  | 
						function getItems(){           var xmlhttp = null;           try{             xmlhttp = new XMLHttpRequest(); // まずXMLHttpRequestオブジェクトをインスタンス化           }catch(trymicrosoft){             try{               xmlhttp =  new ActiveXObject("Msxm2.XMLHTTP");             }catch(othermicrosoft){               try{                 xmlhttp = new ActiveXObject("microsoft.XMLHTTP");               }catch(faild){                 xmlhttp = null;                 alert("ただいまサーバーに障害が発生しております。お使いのサービスは正常に動作しない可能性があります。");               }             }           }           var url = "api.json";           xmlhttp.open("GET", url, true); // 接続           xmlhttp.send(null); // こちらからサーバーへは何も値を送らない           // サーバーからレスポンスが帰ってくるまでの道筋           xmlhttp.onreadystatechange = function(){ // リクエストの処理状態が変更されたら             //ここでは無名関数だが通常の関数を実行させてもよい             if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {               //console.log(xmlhttp.status);               //console.log(xmlhttp.responseText);               //console.log(xmlhttp.responseType);               document.getElementById("result").innerHTML = "取得成功!";               var data = JSON.parse(xmlhttp.responseText) ; // json形式の文字列をjsonに変換               console.log(data);         }  | 
					
コメント
コメントはありません。