2016-06-15 11 views
0

JQuery ajaxファイルのアップロードでacceptヘッダー 'text/xml'を追加するにはどうすればよいですか? PDFファイルをアップロードします。そう406エラーが発生し、JQuery ajaxファイルのアップロードでAcceptヘッダー 'text/xml'を追加する

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であることがヘッダを受け入れる期待:ここ

は私が使用しているコードです。 私はdataType: 'xml'またはヘッダー{Accept: 'text/xml'}を使用しようとしましたが、400のエラーが発生します。

答えて

0

contentType"text/xml"に設定する必要があります。 'text/xmlで' とデータ型: 'テキスト' これはSOこんにちは、私はcontentTypeのを試してみました、それは

jQuery ajax post to web service

+0

を助けるかもしれない答えを参照

var fd = new FormData(document.getElementById('file')); $.ajax({ url: '/myurlhere', type: 'POST', data: fd, cache: false, contentType: "text/xml", dataType: "text", processData: false, success: function(response) { console.log('success... '+response); } }).fail(function(xhr,status,error) { console.log(error); }); 

は、このようなあなたの呼び出しを変更

私は406 Not Acceptableエラーが発生しており、デベロッパーツールをチェックし、Acceptヘッダーがtext/plainとして表示されます。これは、サーバーがtext/xmlを受け入れるためにおそらく動作しない理由です。私はdataTypeを試しました: 'xml'と私は400のエラーを取得します。他のアイデア? – Richard

関連する問題