【发布时间】:2016-06-15 06:15:57
【问题描述】:
如何在 JQuery ajax 文件上传中添加接受标头“text/xml”? 它将上传一个 PDF 文件。
这是我正在使用的代码:
var fd = new FormData(document.getElementById('file'));
$.ajax({
url: '/myurlhere',
type: 'POST',
data: fd,
cache: false,
contentType: false,
processData: false,
success: function(response) {
console.log('success... '+response);
}
}).fail(function(xhr,status,error) {
console.log(error);
});
服务器期望接受标头是 xml,因此会导致 406 错误。 我尝试过使用 dataType: 'xml' 或 header { Accept: 'text/xml' },它会导致 400 错误。
【问题讨论】:
标签: javascript jquery ajax