<!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>无标题文档</title>
<script type="text/javascript" src="ajax_new.js">
</script>
<script type="text/javascript">
window.onload=function()
{
function ajax(url,fnsucc,fnfaild)
{
var oAjax=null;
if(window.XMLHttpRequest)
{
oAjax=new XMLHttpRequest();
}
else{oAjax=new ActiveXObject("Microsoft.XMLHttp");}
oAjax.open('GET',url,true);
oAjax.send();
oAjax.onreadystatechange=function()
{
if(oAjax.readyState==4)
{
if(oAjax.status==200)
{
fnsucc(oAjax.responseText);
}
else{
if(fnfaild)
fnfaild(oAjax.status);
}
}
}
}
var oBt=document.getElementById('bu1');
var oDiv=document.getElementById('div1');
oBt.onclick=function()
{
ajax('1.txt',function(str){
oDiv.innerHTML=str;});
}
}
</script>
</head>
<body>
<input type="button" id="bu1" value="将后台的文件读取显示在div中"/>
<div id="div1" style="width:300px; height:300px; background:#666; overflow:auto;">
</div>
</body>
</html>
txt是我直接放在服务器根目录的文件
没看清楚你的要求,写数据是办不到的,只能说你直接进入后台改掉数据,或是用服务器脚本来解决,然后读取数据,可能存在缓存问题,也是可以解决的。