Display POST AJAX response in a new window

I am sending POST data via ajax using jQuery and returning the binary data of a PDF file.

I would like to do something with this data. Either by providing a download link, or by opening a new tab / window.

I know that sending a user to a site and using GET variables will be easier, but there is a lot of data that is sent through him, and this should be a message.

Is there a way to take the data I get and allow the user to load / see it somehow?

$("#export_pdf").click(function()
{
    var data_serialize = "v1=blah&var2=again&var3=more_info",
    url = "/actions/export-pdf";
    $.ajax({ 
        type: "POST",
        url: url,
        data: data_serialize,
        success: function(data)
        {   
            // data = PDF binary
            // I want to do something with this
        },error: function(data) { alert("error"); }
    });
});
+4
source share
1 answer

I assume that you can get the data and be stored in a data variable.

:

       //open a new window note:this is a popup so it may be blocked by your browser
       var newWindow = window.open("", "new window", "width=200, height=100");

       //write the data to the document of the newWindow
       newWindow.document.write(data);

div, $.ajax.

jsfiddle, , :

http://jsfiddle.net/larryjoelane/d8r3su0m/

jquery $get, . . , . ajax, .

    $("#load_pdf").on("click",function(){


//swap url with a pdf file you have access to for testing
var url = "http://localhost/Responder Manual.pdf";


$.get(url,function(data){


       //open a new window note:this is a popup so it may be blocked by your browser
       var newWindow = window.open("", "new window", "width=200, height=100");

       //write the data to the document of the newWindow
       newWindow.document.write(data);


});

});
+3

All Articles