tags:

views:

271

answers:

1

Hi,

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  A: 
  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/

Nathan
What would be the code which is to be written for the redirection to take place ? Does XmlHttpRequest do this transparently ?
vivekian2
This page has some solutions to the ajax proxy problem: http://developer.yahoo.com/javascript/howto-proxy.html
Nocturne
It depends on your web server - apache supports mod_proxy (http://httpd.apache.org/docs/1.3/mod/mod_proxy.html). I'd be surprised if your web server of choice wouldn't support proxies.
Nathan
Also realized that jQuery lets you make cross domain calls http://docs.jquery.com/Ajax/jQuery.getScript#urlcallback
vivekian2