通信オブジェクトを生成する

書式

httpObj = ajax.x()

httpObj : 通信オブジェクト

説明

 通信オブジェクトを生成するにはajax.x()を使います。Internet ExplorerではActive X、Firefoxなど他のブラウザではXMLHttpRequest()が使用されます。

サンプルコード [実行]

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Sample</title>
<link rel="stylesheet" href="main.css" type="text/css" media="all">
<script type="text/javascript" src="miniajax.js"></script>
<script type="text/javascript"><!--
var httpObj;
function getData(){
httpObj = ajax.x();
if(httpObj){
httpObj.onreadystatechange = function(){
if ((httpObj.readyState == 4) && (httpObj.status == 200)){
$("result").innerHTML = httpObj.responseText;
}
}
httpObj.open("get","sample.txt",true);
httpObj.send(null);
}
}
// --></script>
</head>
<body>
<h1>通信オブジェクト生成</h1>
<form>
<input type="button" value="データ読み込み" onClick="getData()">
</form>
<div id="result"></div>
</body>
</html>