Возврат HttpResponseMessage из API 2 при передаче новой FormData () с использованием Ajax - PullRequest
0 голосов
/ 27 февраля 2020

Пожалуйста, помогите

Я загружаю файл в web api 2 и возвращаю HttpResponseMessage Проблема в том, что каждый раз, когда я возвращаюсь из api 2, он переходит сюда error: function (result, status, xhr) {}, даже если файл загружен успешно. Я подозреваю, что делаю что-то не так со стороны ajax.

Ниже Ajax

 var formData = new FormData();
  $.ajax({
        url: '/api/upload/',
        dataType: 'json',
        type: 'post',
        data: formData,
        contentType: false,
        processData: false,
        done: function (result) {
            debugger;
            $("#loader").show();
        },
        success: function (result) {

        },
        error: function (result, status, xhr) {
          //from API it always goes here

        }

    });

Ниже API

   [HttpPost]
    [Route("api/upload/")]
    public HttpResponseMessage UploadVideo()
    {
      //Uploading happens here

            var chapterReuslts = _moduleAppService.ChapterVideo();

            if (chapterReuslts.Result.success)
            {

                var data = _videoModuleAppService.Create();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK,data);
                return response;


            }

            return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "");
        }

    }
...