2

i am using this j query code

var = "here is path of file"
$(document).ready(function () {
    $("#readFile").click(function () {
        $.get(var, function (data) {
                window.open($("#container").html(data);)
            }, 'text');
    });
});

how to open a file that is located in different directory and i want to display the contents in new window with HTML enable tags all things should be written in j query?

tymeJV
  • 103,943
  • 14
  • 161
  • 157
  • 1
    Your best bet is to build a web service that provides access to the file. There is a new Javascript API that could also work, but browser support is currently quite limited. – Mister Epic Oct 29 '13 at 13:35
  • 1
    `var` is a keyword so `var = "here is path of file"` should cause you problems – Ramunas Oct 29 '13 at 13:42

1 Answers1

1

If i have understood correctly you can use Ajax.

$(document).ready(function () {
    $("#readFile").click(function () {

    var target = '/path/file.html';

    $.ajax({
        url: target,
        contentType: 'application/json; charset=utf-8',
        type: 'POST',
        success: function(data){
            var win = window.open();
            win.document.write(data);
        }
    });

    });
});

Have a look at this answer: How to post form data to a new window using jQuery/AJAX?

Community
  • 1
  • 1
AfromanJ
  • 3,922
  • 3
  • 17
  • 33