0
<script type="text/javascript">
        $(document).ready(function () {
            $("#readFile").click(function () {
                debugger;
                $.get(ServerUrl + "/Vi/Gr/abcd.txt", function (data) {
                    $("#container").html(data);
                }, 'text');

                //$(".text").load(ServerUrl + "/Gr/abcd.txt");

                //$("#container").load(ServerUrl + "/Vi/Gr/abcd.txt");
            });
        });
    </script>



    <button id="readFile" style="margin-top:50px;">Read File</button>

    <div id="container" style="border-style:solid;height:300px;"></div>

Above is my code for reading the contents of a file using jquery and html. I keep getting file not found errors and other errors . For e.g

Uncaught TypeError: Cannot read property 'apply' of undefined.

What I am doing wrong. Please help.

user2998990
  • 970
  • 5
  • 18
  • 36

1 Answers1

0

It's hard to say from the info you have provided.

Depending on where your file is, it could be because your file path is wrong. Are you sure that the file exists there? Another possible cause is that your server does not know how to respond to that url. What is your server running?

Also, javascript can't actually download files directly. See other answers such as Download a file by jQuery.Ajax

Please provide all the errors and more detail as to what the server runs with, because its hard to answer your questions based on the level of detail given here.

Community
  • 1
  • 1
Kristy Hughes
  • 586
  • 1
  • 6
  • 10