我设法用Kendo和AngularJS上传文件,但是我的文件仍然是红色的,并且有一个k-file-error类,文件被上传了,我可以把它们放在后面。为什么会有错误?你能帮帮我吗?
<div class="demo-section k-content">
<div>
<h4>Upload files</h4>
<div class="dropZoneElement">Drag and drop file here</div>
<input name="files"
ng-model="vm.files"
type="file"
kendo-upload
k-async="{ saveUrl: 'http://localhost:5000/api/upload/', removeUrl: 'remove', autoUpload: true, withCredentials: false }"
k-select="onSelect"
k-upload="onUpload"
k-progress="onProgress"
k-success="onSuccess"
options="vm.options"
/>
</div>
<button ng-click="vm.test()">Test</button>
</div>
class DocumentController {
/* @ngInject */
constructor($scope, authTokenService) {
this.name = 'document';
$scope.onSelect = e => {
// console.log(e.files);
};
$scope.onUpload = e => {
const token = authTokenService.getToken();
// Check if the token is expire
if (token && authTokenService.isExpired(token)) {
authTokenService.setToken();
}
const xhr = e.XMLHttpRequest;
if (xhr) {
xhr.addEventListener('readystatechange', () => {
if (xhr.readyState === 1) {
// Add the token to the header
if (token) {
xhr.setRequestHeader('Authorization', `Bearer ${token}`);
}
}
});
}
};
$scope.onSuccess = e => {
console.log(e);
};
$scope.onProgress = e => {
// console.log(e);
};
this.options = {
dropZone: '.dropZoneElement'
};
}
}
export default DocumentController;发布于 2016-11-11 16:58:45
您应该从服务器响应中返回有效的JSON结果。即使是return json(true)也应该可以工作。
https://stackoverflow.com/questions/40533908
复制相似问题