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
asked Mar 8, 2009 at 2:21
vivekian2
3,9549 gold badges37 silver badges41 bronze badges
1 Answer 1
- Use some sort of ajax framework (or XmlHttpRequest) that would read a file, parse it and display it.
- 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/
answered Mar 8, 2009 at 2:30
Nathan
2,0621 gold badge14 silver badges18 bronze badges
Sign up to request clarification or add additional context in comments.
4 Comments
vivekian2
What would be the code which is to be written for the redirection to take place ? Does XmlHttpRequest do this transparently ?
Debajit
This page has some solutions to the ajax proxy problem: developer.yahoo.com/javascript/howto-proxy.html
Nathan
It depends on your web server - apache supports mod_proxy (httpd.apache.org/docs/1.3/mod/mod_proxy.html). I'd be surprised if your web server of choice wouldn't support proxies.
vivekian2
Also realized that jQuery lets you make cross domain calls docs.jquery.com/Ajax/jQuery.getScript#urlcallback
lang-js