2012-02-12 41 views
1

以下是代碼。 「core/bcsheet.php」返回PDF文檔,但ajax顯示爲html代碼。我如何向用戶展示PDF?以PDF格式打開ajax退回文檔

function ajaxPost() { 
    form = $("#dbview"); 
    formData = form.serialize(); 
    formUrl = "core/bcsheet.php"; 
    formMethod = form.attr('method'); 

    $.ajax({ 
     url: formUrl, 
     type: formMethod, 
     dataType: "html", 
     cache: false, 
     data: formData, 
     success: function (html) { 
      var win = window.open('', 'childWindow', 'location=yes, menubar=yes, toolbar=yes'); 
      win.document.open(); 
      win.document.write(html);   
      // win.print(); 
      win.document.close();   
     //win.close(); 
     } 
    }); 
}; 
+0

我不認爲你有很多選擇,你可以指向(PDF文檔的location.href = /路徑/到/ pdf),瀏覽器將打開一個下載對話框,否則,如果用戶已配置爲在瀏覽器中打開PDF,它將在任何PDF查看器用戶安裝時顯示爲pdf – Rafay 2012-02-12 14:52:52

回答