2016-07-15 12 views
0

PDFファイルを生成するためにユーザーが入力する必要があるフォームがWebサイトにあります。フォームにエラーがある場合、サーバーはエラーのリストでjsonオブジェクトで応答し、そうでない場合はPDFファイル(文字列として)で応答します。私はMagnifico-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); 

        } 
       } 
      } 
     }); 

    }); 

答えて

0

これは、同じ問題を持つ人のために役に立つかもしれません。代わりに応答としてPDFファイルを送信するのでは、私は、サーバーの一時的なPDFファイルを生成し、応答として、そのファイルへのパスを送ることにしました。それから、magnificopopupにiframeの中に表示することができます。

関連する問題