简体   繁体   中英

How to fetch a file on a web server using JavaScript?

I am trying to write a small documentation tool to be used from the browser. It would need to fetch source code files from a web server. What would be the appropriate way to fetch files from JavaScript itself and then read them so they can be parsed? The file to be fetched is on a different web server.

thanks in advance, vivekian

  1. Use some sort of ajax framework (or XmlHttpRequest) that would read a file, parse it and display it.
  2. You'll have to create a proxy to that other server. Otherwise you're going to run into security exceptions.

Given your main url http://www.x.com/help.html , and the source files that are located at http://www.x321.com/src/ , you're going to create a proxy at http://www.x.com/proxy/ to http://www.x321.com/src/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM