Read A Server Side File Using JavaScript

后端 未结 5 1169
情书的邮戳
情书的邮戳 2021-02-04 03:11

I have on my web server a JS script that I want to be able to read files. My filesystem is like this:

> Root
index.html
read.js
> files
    file.txt
         


        
5条回答
  •  攒了一身酷
    2021-02-04 03:53

    This is a very simple task if you are using JQuery - The below example will perform an HTTP GET request (using XMLHttpRequest.as referenced above) and will put the contents into an HTML DOM object with the ID of "result". It will also throw an alert box up once the load is completed.

    $( "#result" ).load( "files/file.txt", function() {
      alert( "Load was performed." );
    });
    

提交回复
热议问题