0

Im making a jquery ajax post call, and the .success method is being called, but the response data is empty.

Javascript:

$.ajax({
        type: 'post',
        url: '/MediaUploader/fileUpload',
        data: formData,
        contentType: false,
        processData: false,
    })
        .done(function (data) {
            //Data 
        })

The success function is called, but the data is empty.

Controller:

[HttpPost]
public ActionResult FileUpload() {
    //code
    file.SaveAs(pathToSave);
    return Json(str_image);

When called, the response is empty: no response

However, commenting out the file.SaveAs, or returning before it, causes the respond to go through:

[HttpPost]
public ActionResult FileUpload() {
    //code
    //file.SaveAs(pathToSave);
    return Json(str_image);

yes response

When debugging, the file.SaveAs doesn't throw any exceptions, and in both cases the return is reached. Also, this problem only is occurring on the remote. On local host both versions work fine.

The response doesnt go through only after the file.SaveAs on remote server.

Community
  • 1
  • 1
Narek Daduryan
  • 235
  • 1
  • 5

1 Answers1

0

Fixed, it was a problem with directory permissions.

(weird, i didnt think it's an issue because the files were being uploaded successfully anyway)

Narek Daduryan
  • 235
  • 1
  • 5
  • You should have a try-catch block to wrap your code to capture any exception and send out a "success" or "failure" response to your ajax call. Another point is to capture the ajax error and write into the console: failure: function () { console.log("Error in ajax call"); } – TejSoft Aug 23 '18 at 04:13