サーバー上のXMLデータを読み込む

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="ja">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Sample</title>
<link rel="stylesheet" href="css/main.css" type="text/css" media="all">
<script type="text/javascript" src="js/prototype.js" charset="shift_jis"></script>
<script type="text/javascript"><!--
Event.observe(window, "load", function(){
$("loadButton").onclick = function(){
new Ajax.Request("news.xml", {
method : "get",
parameters: "cache=" + (new Date()).getTime(),
onSuccess : function(httpObj){
var xmlObj = httpObj.responseXML;
var newsTitle = xmlObj.getElementsByTagName("title")[0].firstChild.nodeValue;
var newsCont = xmlObj.getElementsByTagName("content")[0].firstChild.nodeValue;
$("result").innerHTML = newsTitle + "<br>"+newsCont;
}
});
}
}, false);
// --></script>
</head>
<body>
<h1>サーバー上のXMLデータを読み込む</h1>
<form action="./dummy.cgi">
<input type="button" value="読み込み" id="loadButton">
</form>
<div id="result">...</div>
</body>
</html>
サンプルを実行
[戻る]
prototype.jsパーフェクトリファレンス説明などは本書を参考にしてください。