当前位置:首页>正文

ajax怎么提取网路文本内容 ajax不能成功读取本地txt文件

2023-07-29 00:27:31 互联网 未知

ajax怎么提取网路文本内容?

使用copyjquery, 什么是jquery我想你应该知道的,引入jquery后使用百以下代码便可以加度载网络文本。
$.ajax(http..... 123. txt, function(res) {
console.log(res)

})

谢谢采纳!

ajax不能成功读取本地txt文件

那个不是 磁盘文件的地址 ,是一个网页地址 ,ajax异步提交
xmlhttp.open("GET","/ajax/test1.txt",true)
的三个参数 第一个是get 方式还是 post 方式 第二个是 提交到的地址 ,第三个参数 是同步提交还是异步提交, 你在写一个servlet 或者 action 提交过去 ,.xmlhttp.responseText是到指定url 运行后 返回的 值, 你再多看一下ajax的原理

关于jQuery ajax读取txt文本的问题!

<!DOCTYPE html>
<html>
  <head>
    <title>文件示例</title>
    <meta name="name" content="content" charset="utf-8">
  </head>
  <body>
      <input type="file" id="file" />
      <input type="button" onclick="readText()" value="File Button">
      <div id="tt">

      </div>
  </body>
</html>
<script charset="utf-8">
window.onload=function () {
  if(typeof(FileReader)=="undefined")
  {
    alert("你的浏览器不支持文件读取")
    document.write("")
  }else
  {
    alert("你的浏览器支持文件读取")
  }
}
  function readText() {
      var file=document.getElementById("file").files[0]
      var reader=new FileReader()
      reader.readAsText(file)
      reader.onload=function(data)
      {
        var tt=document.getElementById("tt")
        tt.innerHTML=this.result
      }
    }

</script>