「AJAX」XMLHttpRequestオブジェクトのサンプル
構文
variable=new XMLHttpRequest();
JSコード
<script>
function loadXmlFunc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{
// IE7+, Firefox, Chrome, Opera, Safari browser run code
xmlhttp=new XMLHttpRequest();
}
else
{
// IE6, IE5 browser run code
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","/try/ajax/ajax_info.txt",true);
xmlhttp.send();
}
</script>
htmlコード
<div id="myDiv"><h2>use AJAX update contents</h2></div> <button type="button" onclick="loadXmlFunc()">update contents</button>