剑道上传成功时出现k-file-error

时间:2016-11-10 17:44:15

标签: angularjs kendo-ui ecmascript-6

我设法使用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;

1 个答案:

答案 0 :(得分:0)

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

相关问题