我假设您能够检索数据并将其存储在数据变量中.
您可以在成功函数中尝试以下操作:
//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函数中的success函数显示该div.
这是一个jsfiddle,如果你想试验它将帮助你:
我用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("",height=100");
//write the data to the document of the newWindow
newWindow.document.write(data);
});
});