Skip to content Skip to sidebar Skip to footer

Reading A File Using Javascript

How do I read contents from a server side file using javascript?

Solution 1:

Ask the web server for it with Ajax. In jQuery speak, for instance:

jQuery.get('path/to/file/on/server.txt', null, function(data, status) {
    // your file contents are in 'data'
});

Solution 2:

using Ajax (XmlHttpRequest) e.g. using jQuery:

jQuery.get( url, [data], [callback], [type] )

Solution 3:

This is not possible using plain javascript. Javascript runs in the client browser and you cannot access a file in server. You can use AJAX to do this.

Solution 4:

The quick answer is "you can't".

If you make the server side file accessible through your web server, you can use an xmlhttprequest, a.k.a ajax, to retrieve it.

Post a Comment for "Reading A File Using Javascript"