首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >K-file- kendo上传成功时出错

K-file- kendo上传成功时出错
EN

Stack Overflow用户
提问于 2016-11-11 01:44:15
回答 1查看 394关注 0票数 0

我设法用Kendo和AngularJS上传文件,但是我的文件仍然是红色的,并且有一个k-file-error类,文件被上传了,我可以把它们放在后面。为什么会有错误?你能帮帮我吗?

代码语言:javascript
复制
<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;
EN

回答 1

Stack Overflow用户

发布于 2016-11-11 16:58:45

您应该从服务器响应中返回有效的JSON结果。即使是return json(true)也应该可以工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40533908

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档