我正尝试使用以下脚本通过ajax / jquery使用REST api将文件上传到远程服务器,但由于错误请求,它返回400错误。我已经使用curl测试了端点,curl给出了正确的响应,并且正在上传文件。
$(document).ready(function () {
$("#btnSubmit").click(function (event) {
//stop submit the form,we will post it manually.
event.preventDefault();
fire_ajax_submit();
});
});
function fire_ajax_submit() {
// Get form
var form = $('#fileUploadForm')[0];
alert(form.files[0]);
var data = new FormData(form);
data.append("CustomField","This is some extra data,testing");
$("#btnSubmit").prop("disabled",true);
$.ajax({
type: "POST",enctype: 'multipart/form-data',url: "http://10.13.20.166:5332/fileUploadtoFolder",data: data,processData: false,contentType: false,cache: false,timeout: 600000,success: function (data) {
$("#result").text(data);
console.log("SUCCESS : ",data);
$("#btnSubmit").prop("disabled",false);
},error: function (e) {
$("#result").text(e.responseText);
console.log("ERROR : ",e);
$("#btnSubmit").prop("disabled",false);
}
});
}