使用PDF从ajax结果加载嵌入控件

时间:2015-12-07 21:31:58

标签: jquery html5 embed

我在DIV里面有一个ID为“奖励”的DIV,我有一个EMBED ......

<div id="award">
  <embed src="" width="400" height="500">
</div>

在我的点击绑定中,我正在调用一个AJAX控件

  $.ajax({
url: "handlers/loadPDFHandler.ashx", //or your url

data: {
  'FileName': "Bid" + record + ".pdf"
},
success: function (data) {
// $("#target embed").attr("src", "http://www.oldsite.com/bids/bid" + record + ".pdf");
//  alert(data);
  $("#target embed").body.update(display.data);

},
error: function (data) {
  alert('Bid PDF not found.');
},
});

AJAX调用是

  var fileName = context.Request["FileName"];

  var storageConnectionString = System.Configuration.ConfigurationManager.AppSettings["BlobStorageConnectionString"];
  var blobContainerName = System.Configuration.ConfigurationManager.AppSettings["BlobStorageContainerName"];

  CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);

  CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

  CloudBlobContainer container = blobClient.GetContainerReference(blobContainerName);

  CloudBlockBlob blockBlob2 = container.GetBlockBlobReference(fileName);

  blockBlob2.FetchAttributes();
  long fileByteLength = blockBlob2.Properties.Length;
  Byte[] myByteArray = new Byte[fileByteLength];
  blockBlob2.DownloadToByteArray(myByteArray, 0);


  context.Response.ContentType = "application/pdf";
  context.Response.AddHeader("Content-Length", myByteArray.Length.ToString());
  context.Response.AppendHeader("content-disposition", "inline; filename=" + fileName);
  context.Response.BinaryWrite(myByteArray);
  context.Response.End();

这就是我失败的地方...... 我能够在警报中看到PDF文档字节数组......

如何使用AJAX调用的结果填充EMBED?

我假设这一行

$("#target embed").body.update(display.data);

是我需要执行操作的地方,但我对如何实际完成它感到迷茫。

1 个答案:

答案 0 :(得分:-1)

解决了 -

$scope.$on('failedPackages', function(event, args){
        console.log(event)
        console.log(args)
    });