【发布时间】:2017-02-27 07:15:05
【问题描述】:
我需要使用 ajax 向我的服务发送带有 id、name 和文件 (PdfBytes) byte[] 的数据。
如何将我的 PDF 文件添加到 var pdf 并将其添加到我的 ajax。
我的代码
var PdfBytes;
//Tried to fill PdfBytes with get,didnt work
$.get('http://testservices.xxx/PdfService/MYTest.pdf', function(data)
{
PdfBytes=data;
});
var ConvertHtmlToPdfAndSendEmail = {
"PdfBytes":PdfBytes,
id": id,
"Name": name
};
$.ajax({
type: "POST",
data: JSON.stringify(ConvertHtmlToPdfAndSendEmail),
dataType: 'json',
url: "http://testservices.xxx/ConvertHtmlToPdfAndDownload",
contentType: 'application/json; charset=utf-8',
async: true,
cache: false,
success: function (result) {
//my code
},
error: function (req, err) {
//my code
}
})
在服务器中我得到 PdfBytes 为空
函数期望得到byte[] PdfBytes
了解我如何将我的 pdf 从我的电脑上传到 var PdfBytes,并以 ajax 的形式发送到我的服务。
【问题讨论】:
标签: javascript jquery ajax