Javascript 通过Ajax和FormData发送文件失败

Javascript 通过Ajax和FormData发送文件失败,javascript,jquery,ajax,Javascript,Jquery,Ajax,我试图在Jquery中使用Ajax发送一个文件,之前创建了一个FormData。这是我的代码: var inputFileImage = document.getElementById('uploadImage'); var file = inputFileImage.files[0]; var data = new FormData(); data.append('archivo',file); jQuery.ajax({ url: '/servi

我试图在Jquery中使用Ajax发送一个文件,之前创建了一个FormData。这是我的代码:

var inputFileImage = document.getElementById('uploadImage');
var file = inputFileImage.files[0];
var data = new FormData();                  
data.append('archivo',file);

jQuery.ajax({
    url: '/services/rpc.php',
    type: 'post',
    data: {functionName: 'saveProfileImage', data : data},
    contentType:false,
    processData:false,
})
.done(function(response) {
    alert(response);            
}.bind(this))
.fail(function(response) {
     alert('Sorry, there was an unexpected error, please try again later.\n\nInformation about the error:\n'+response);
        });
这个ajax总是转到
fail
函数,如果我将
processData
更改为
true
则返回另一个错误,称为error:TypeError:“append”在未实现接口FormData的对象上调用


谢谢你的帮助

processData必须关闭才能发送二进制数据。FormData元素完全用作二进制数据,而
数据:{}
需要处理。在这种情况下,必须将其他参数附加到formData

var data = new FormData();                  
data.append('archivo',file);               
data.append('functionName','saveProfileImage');

jQuery.ajax({
    url: '/services/rpc.php',
    type: 'post',
    data: data,
    contentType:false,
    processData:false,
});

archivo是您试图检索图像的DomeleElement的名称?当您使用ajax发送表单数据时,您不能将其他信息作为json发送。我们需要将其作为表单字段值发送