国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

PHP開発基本チュートリアルのサーバー応答

1. サーバーの応答を取得する方法

サーバーの応答を取得するには、XMLHttpRequest オブジェクトの responseText 屬性または responseXML 屬性を使用できます。


66.png

2. responseText 屬性

サーバーからのレスポンスが XML でない場(chǎng)合は、responseText 屬性を使用してください。

responseText プロパティは応答を文字列として返すため、次のように使用できます:

Use 4_1.php to read information from 4_2.txt

4_1.php code

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","4_2.txt",true);
xmlhttp.send();
}
</script>
</head>
<body>
<h2>AJAX</h2>
<button type="button" onclick="loadXMLDoc()">通過(guò)AJAX改變內(nèi)容</button>
<div id="myDiv">AJAX</div>
</body>
</html>

4_2.txt code

* AJAX 是一種用于創(chuàng)建快速動(dòng)態(tài)網(wǎng)頁(yè)的技術(shù)。

3. responseXML 屬性

サーバーからの応答が XML であり、XML オブジェクトとして解析する必要がある場(chǎng)合は、responseXML 屬性を使用してください:

4_4.xml ファイルをリクエストし、応答を解析します ( 平たく言えば、4_3.php ページは更新されず、4_4.xml の応答コンテンツを読み取ります):

4_3.php code

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
function loadXMLDoc()
{
var xmlhttp;
var txt,x,i;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    xmlDoc=xmlhttp.responseXML;
    txt="";
    x=xmlDoc.getElementsByTagName("title");
    for(i=0;i<x.length;i++){
    		txt=txt+x[i].childNodes[0].nodeValue+"<br/>";
    	}
    document.getElementById("myDiv").innerHTML=txt
    }
  }
xmlhttp.open("GET","4_4.xml",true);
xmlhttp.send();
}
</script>
</head>
<body>
<h2>AJAX</h2>
<button type="button" onclick="loadXMLDoc()">通過(guò)AJAX改變內(nèi)容</button>
<div id="myDiv">AJAX</div>
</body>
</html>

4_4.xml code

リーリー
學(xué)び続ける
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script> function loadXMLDoc() { var xmlhttp; var txt,x,i; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { xmlDoc=xmlhttp.responseXML; txt=""; x=xmlDoc.getElementsByTagName("title"); for(i=0;i<x.length;i++){ txt=txt+x[i].childNodes[0].nodeValue+"<br/>"; } document.getElementById("myDiv").innerHTML=txt } } xmlhttp.open("GET","4_4.xml",true); xmlhttp.send(); } </script> </head> <body> <h2>AJAX</h2> <button type="button" onclick="loadXMLDoc()">通過(guò)AJAX改變內(nèi)容</button> <div id="myDiv">AJAX</div> </body> </html>
提出するリセットコード
  • おすすめコース
  • コースウェアのダウンロード