「 1/index.txt
の内容を、そのままコピーして持ってくる」
です。よろしくお願い申し上げます。
document.getElementById("id名").innerText=index;
とか。コピーしてもってくるというかそのまま反映させるというか。
サーバ上の"1/index.txt"の内容をページ上にそのまま表示したい,との理解で良かったでしょうか。であれば,こんな感じでしょうか。(windofjulyさんとTYCOONさんの回答を一つにまとめただけのコードになりますが...。)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <title>JavaScript Test</title> <script> function createHttpRequest() { var request = null; try { request = new XMLHttpRequest(); } catch(e) { try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { request = new ActiveXObject("Microsoft.XMLHTTP"); } } return request; } window.onload = function() { var request = createHttpRequest(); request.open('get', '1/index.txt', true); request.onreadystatechange = function() { if (request.readyState == 4) { var index = document.getElementById('index'); if (request.status != 200) { index.innerHTML = 'エラーが発生しました'; } else { try { index.innerText = request.responseText; } catch (e) { index.innerHTML = request.responseText; } } } }; request.send(''); } </script> </head> <body> <div> <pre id="index"></pre> </div> </body> </html>
ありがとうございます。具体的に示していただき、大変助かりました。