目前做的是一个web端的绘图,功能要求是能保存能打开(不是另存为)。我用的是VML做的。
本地运行的效果是(有两个文件,一个index.htm一个是drawa.htm),打开index,画布上就会出现drawa.htm里面画的内容,并且可以进行修改或者增加元素等功能。关闭的时候弹出提示框进行存储,依旧存在drawa.htm里面问题是,我现在用的读取drawa.htm里面的代码用的是之前一大神给的
<script language='jscript'>
var xhr=window.ActiveXObject?new ActiveXObject("microsoft.xmlhttp"):new XMLHttpRequest();
xhr.open("get","drawa.htm?now=" + new Date().getTime(), true);
xhr.onreadystatechange=function(){
  if(4==xhr.readyState&&(200==xhr.status||0==xhr.status))
xhr.responseText;
}
xhr.send(null)
document.getElementById("div1").innerHTML=xhr.responseText.replace(/>/g,'>\n').replace(/ = /g,'=').replace(/\: /g,':').replace(/\; /g,';')
</script>
这串代码在本地运行是毫无问题的。但是放在服务器上却没有显示(因为考虑了ajax缓存的问题所以第三行代码改成了+ new date的形式),请问如何解决,或者是换一套存储方法也行
上面就是问题的全部,下面是我对问题的补充描述,为了以防万一,我在界面里面加了个按钮。代码和document.getElementById("div1").innerHTML=xhr.responseText.replace(/>/g,'>\n').replace(/ = /g,'=').replace(/\: /g,':').replace(/\; /g,';')是一样的,网页放到服务器上之后,打开是没有图像的,但是点了这个按钮之后图像就可以刷出来了,这是什么原因本人学JS不久。希望大家别嫌弃~

解决方案 »

  1.   

    document.getElementById("div1").innerHTML=xhr.responseText.replace(/>/g,'>\n').replace(/ = /g,'=').replace(/\: /g,':').replace(/\; /g,';')你这个应该放到回调函数里面,应为是异步的,ajax还没有返回呢。在xhr.send(null)后就执行上面那句了,获取不到responseText的var xhr=window.ActiveXObject?new ActiveXObject("microsoft.xmlhttp"):new XMLHttpRequest();
    xhr.open("get","drawa.htm?now=" + new Date().getTime(), true);
    xhr.onreadystatechange=function(){
      if(4==xhr.readyState&&(200==xhr.status||0==xhr.status))
    document.getElementById("div1").innerHTML=xhr.responseText.replace(/>/g,'>\n').replace(/ = /g,'=').replace(/\: /g,':').replace(/\; /g,';')///////放回调里面
    }
    xhr.send(null)
    //document.getElementById("div1").innerHTML=xhr.responseText.replace(/>/g,'>\n').replace(/ = /g,'=').replace(/\: /g,':').replace(/\; /g,';')还有个问题就是设置innerHTML,如果内容包含js代码,是不会自动运行的,你的是vml只有ie支持,你可以给script标签添加 defer="defer"属性解决js代码不运行问题