-2

I have a sql file stored in my local PC. I need to display the contents of this file on a webpage using jquery.Any code snippet that i can get to make this work ?

I have tried using .load(path) function but am not getting any result.

Here is what i have tried:

        $(document).ready(function () {
            $("#query").change(function () {
                var query = $("#query option:selected").text();

                var path = "./resources/WEB-INF/sqlQueries/" + query + ".sql";
                alert(path);
                $("#queryTA").load(path);
            });
        });

query is a combobox with list of available queries. Based on the option selected, I need to read the contents of the corresponding .sql file and display the contents inside a TextArea with id: queryTA

Ambkrish
  • 837
  • 1
  • 6
  • 7
  • can you post the jquery code you tried..also where you are trying to show the data ..is it inside a div? please more specific with the question..else nobody can help you. – Sachu May 12 '15 at 09:10
  • If you just want to show the contents of the sql file (not the result of the query), you could just search for "jquery load textfile to textarea", for example http://stackoverflow.com/questions/19020484/loading-txt-file-into-textarea-javascript could help. – mameluc May 12 '15 at 09:18
  • The "path" alert is correct? – Sachu May 12 '15 at 10:50

1 Answers1

0

Try this

$(document).ready(function () {
            $("#query").change(function () {
                var query = $("#query option:selected").text();

                var path = "./resources/WEB-INF/sqlQueries/" + query + ".sql";
                alert(path);
                jQuery.get(path, function(data) {
               $('#queryTA').html(data);
            });
        });
Sachu
  • 7,555
  • 7
  • 55
  • 94