0
我有问题发送文件到服务器用ajax提交。我用var xhr = new XMLHttpRequest();
和$.ajax({});
尝试了很多方法,但总是给出错误Uncaught TypeError: Illegal invocation
。我也使用processData: false
,但在这种情况下,我将所有表单域分隔开。用ajax表单发送文件数据提交
我对Ajax代码是:
var fd = new FormData();
fd.append('file', $('#file')[0].files[0]);
fd.append('name', 'test');
$.ajax({
url: "uploadFile.php",
data: fd,
cache: false,
contentType: false,
// processData: false,
type: 'POST',
success: function(data, textStatus, jqXHR){
console.log('success');
},
error: function(jqXHR, textStatus, errorThrown){
console.log('error');
}
});
在此我只拿到了name
场与产值test
,但不file
。 有人请让我知道我错了。
表单代码是否需要并且您是否添加了jQuery库? –
也许在您的数据中有'fd.value' – Mihai
我在我的html 中添加了jquery库,并且我的html是'
' –