0
我在我的網站上有一個表格,用戶需要填寫以便生成PDF文件。如果表單中存在錯誤,服務器將使用帶有錯誤列表的json對象進行響應,否則將使用PDF文件作爲響應(以字符串形式)。我試圖在Magnific-Popup(https://www.npmjs.com/package/magnific-popup)中顯示該PDF文件。在Magnific-Popup模式下顯示PDF文件
$('.preview-button').on('click', function (e) {
event.preventDefault();
var theLink = $(this);
var formElement = theLink.closest("form");
$.ajax({
url: theLink.attr('href'),
method: 'GET',
data: formElement.serialize(),
success: function (response, textStatus, jqXHR) {
var contentType = jqXHR.getResponseHeader("content-type") || "";
if(contentType.indexOf('pdf') > -1){
// How can I tell to magnific popup to display the response as PDF?
$.magnificPopup.open({
// tell magnific popup to use the response...
type: 'iframe',
closeOnBgClick: false
});
}
else{
if (response.hasOwnProperty('errors')){
// Form has error, show them
alert(response.errors);
}
}
}
});
});