Angularjs:错误:'追加'对未实现接口FormData的对象调用.jQuery.param/ad
Angularjs: Error: 'append' called on an object that does not implement interface FormData. jQuery.param/add
我使用https://github.com/danialfarid/ng-file-upload插件来管理我的文件上传,下面是我的代码。
HTML
<form name="form">
Single Image with validations
<div class="button" ngf-select ng-model="file" name="file" ngf-pattern="'image/*'"
ngf-accept="'image/*'" ngf-max-size="20MB" ngf-min-height="100"
ngf-resize="{width: 100, height: 100}">Select</div>
Multiple files
<div class="button" ngf-select ng-model="files" ngf-multiple="true">Select</div>
Drop files: <div ngf-drop ng-model="files" class="drop-box">Drop</div>
<button type="submit" ng-click="upload()">submit</button>
</form>
控制器
// upload on file select or drop
$scope.upload = function (file) {
file = new FormData();
file = {'file': file};
imageFind.search(file, $scope.documentsOffsetStart, $scope.titleSorting)
.then(
function (response) {
console.log('Success ' + response.config.data.file.name + 'uploaded. Response: ' + response.data);
},
function (response) {
console.log('Error status: ' + response.status);
}, function (evt) {
console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
});
};
图像查找服务
]).factory('imageFind', [
'imageService', 'ApiService',
function (imageService, ApiService) {
return {
search: function (file, start, sort) {
var formData, params={};
if (start == null) {
start = 0;
}
if (sort == null) {
sort = "";
}
var data = {
start: start,
sort: sort
};
data = $.param(data);
var config = {'Content-Type': undefined};
return ApiService.post(imageFindPint, data, config);
}
};
}
]);
上传图像时出现以下错误:错误:在未实现接口FormData的对象上调用了"append"。jQuery.param/add
你看到我做错什么了吗?
通过<button type="submit" ng-click="upload('file')">submit</button>
这应该能解决问题。
在控制器中//file=new FormData();//file={'file':文件};
可以删除,但需要将FormData()添加到服务中。
相关文章:
- JQuery Deferred Ajax,将结果保存在调用对象中
- 无法从JavaScript中的函数调用对象属性
- 在Javascript中调用对象方法时不是函数类型错误
- 正在调用对象中设置的匿名函数,但未得到预期结果
- 为什么需要“this”来调用对象内部的函数
- 如何从onClick事件调用对象函数
- 是否可以在不加对象名称前缀的情况下调用对象的函数
- 对象-在定义对象之前先调用对象
- console.log表示,当我调用对象的任何成员时,对象都是未定义的
- 正在调用对象的方法
- console.log是否调用对象的toString方法
- Javascript”;无效的调用对象“;xml错误
- 如何在javascript中调用对象键(codecademy)
- 如果我丢失了调用对象,如何杀死 setInterval()/setTimout()
- 如何在对象生成器外部调用对象属性值
- JavaScript:动态调用对象内的函数
- 如何动态加载 JavaScript 对象或调用对象方法
- IE9 在 iframe 中打印 PDF 时出现“无效调用对象”
- 在方法调用对象之外访问变量而不使它们全局化(可能吗?
- Javascript - 在对象中调用对象的方法,给出错误:“对象没有方法getStartPoint”