weixin_33695082 2012-03-18 15:56 采纳率: 0%
浏览 18

使用ajax从文件读取

I am trying to read from a file on the local machine using Ajax.The file it is reading from is a text file having numbers like 1 2 3 4 5 but when I run the code in a browser in spite of all the formatting the numbers appear separated by a space rather then on new lines.If someone could tell me how to get the numbers printed out in the format that they originally exist,I would be thankful

Here is the code:

<html>
<script>
var oRequest;
var i;
if(document.all) {

oRequest = new ActiveXObject("Microsoft.XMLHTTP")
}
else {
oRequest = new XMLHttpRequest();
}
oRequest.open("GET", "file:///C:/testing.txt", false);
oRequest.send(null);
textToBeWritten = oRequest.responseText;
document.write(textToBeWritten+"<br />");
</script>
</html>
  • 写回答

1条回答 默认 最新

  • weixin_33725126 2012-03-18 15:58
    关注

    You need to convert text-file newlines ( ) to HTML newlines (<br />) like so:

    textToBeWritten = oRequest.responseText.replace("
    ", "<br />");
    
    评论

报告相同问题?

悬赏问题

  • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功