Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
173
rated 0 times [  175] [ 2]  / answers: 1 / hits: 15672  / 12 Years ago, fri, january 4, 2013, 12:00:00

Using ajax I am getting the response as a PDF base64 data. Here in this example I am showing it in a new window, instead of that I want to show the PDF in a modal popup. Is there any way to do that?



$.ajax({
type : POST,
url : getPrintablePDF,
dataType : json,
contentType : 'application/json; charset=utf-8',
data : JSON.stringify(params),
success : function(data) {
//console.log(data);
var myResponse = eval(data);
window.open('data:application/pdf;base64,' + myResponse.base64EncodedResponse);

}
});

More From » html

 Answers
36

Try using <object /> or <embed /> or using <iframe />


I am giving an example with <iframe /> as it is supported by all the browsers.


$.ajax({
type : "POST",
url : getPrintablePDF,
dataType : "json",
contentType : 'application/json; charset=utf-8',
data : JSON.stringify(params),
success : function(data) {
var myResponse = eval(data);
$("<iframe />") // create an iframe
// add the source
.attr('src', 'data:application/pdf;base64,' + myResponse.base64EncodedResponse)
.appendTo('.modal-body'); // append to modal body or wherever you want
}
});

[#81087] Thursday, January 3, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bradley

Total Points: 555
Total Questions: 102
Total Answers: 99

Location: Tajikistan
Member since Fri, Nov 27, 2020
4 Years ago
;