0

I am trying to add a functionality where a user can browse a file and display the content of the file on the div.

<!DOCTYPE html>
<html>
    <head>
    </head>
<body>
    <input id='inpFile' type='file'>
    <button id='submit'>Submit</button>  
    <div id='content'>Hello</div>
</body>
</html>

JS:

$('#submit').click(function() {
    $.get($('#inputFile').val(), function(data) {
        $('#content').html(data);
    });
}

Nothing is getting updated in the div element and no error is returned. Please suggest.

UPDATE:

I recently discovered that $.get() basically does an http request. But my file is present locally in the system, so is the reason above JS code is not working.

But I can't use HTML5 File or FileReader API as I am working on IE-8, it doesn't support HTML5.

So should I copy the file to the server and then use $.get() to get the file contents to div.

Please suggest.

Ejaz
  • 1,504
  • 3
  • 25
  • 51

0 Answers0