javascript-Ajax-
javascript
[javascript]
window.addEventListener('load',
function(event){
var elem = document.getElementById('btn_loadtext');
elem.addEventListener('click',loadText,false);
},false);
function loadText(event){
var req = new XMLHttpRequest();
req.open('GET','aozora.txt');
req.onreadystatechange = function(event){
if(req.readyState == 4){
var text = document.getElementById('text');
if(req.status == 200){
text.innerHTML = req.responseText;
}else{
text.innerHTML = '読み込みエラー';
}
}
};
req.send();
}
[/javascript]
html
テキスト読み込み