我有一个asp.net ASHX处理程序,它接受xml数据作为输入并生成pdf文档并将其返回到响应,如下所示:
public override void NowProcessTheRequest(XmlWriter xw)
{
var bytes = get pdf bytes from service based on input xml xw
var fileName="test";
context.Response.ContentType = "application/pdf";
context.Response.Headers.Add("Content-Disposition",
string.Format("inline; filename=report_{0}_{1}.pdf", fileName, DateTime.Now.ToString("MM_dd_yyyy")));
context.Response.Write(bytes);
context.Response.Flush();
}
现在我想在javascript的新窗口中打开生成的pdf。
我无法使用" window.open"因为我不知道如何在体内传递xml。那么我有什么选择从javascript调用这个ashx处理程序并发布一个xml数据并在新窗口中打开响应pdf。?
答案 0 :(得分:0)
echo
xml
输入?
var xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><abc>123</abc>";
$.post("/echo/xml/", {xml:xml}, "xml")
.then(function(xml) {
var res = $(xml).find(":root")
, popup = window.open("", "popup", "width=600,height=400");
popup.document.body.innerHTML = res.get(0).outerHTML;
popup.focus();
popup.print();
});