Przemysław Zamorski
Przemysław Zamorski

Reputation: 741

Ajax doesn't return succes or error but is done and complete

Is it possible to make an ajax request which doesn't call either success or error on completion and still gives back a done and complete status?

function execute_given_operation(operation, operation_data, succes_function, error_function, done_function) {
    $.ajax({
        async: true,
        crossDomain: true,
        url: "/framework/ope/" + operation,
        method: "POST",
        dataType: 'json',
        data: operation_data,
        succes: function (data) {
            succes_function;
        },
        error: function (data) {
            error_function(data);
        },
        complete: function (xhr, textStatus) {
            console.log(xhr.status);
        }

    }).done(function (response) {
        console.log('x', response);

    });
}

function contact_accomplish() {

$("#load_assign_gif").css("display", "block");

execute_given_operation("LEAD_INBOX_MENU_KONTAKT_WYKONANY","{\"LEADYLEADID\":" + window.object.LEADID + " }\n",
    function(){console.log("jupi");},
    function(){console.log("nope");},
    function(){});
}

So when I call the function contact_accomplish, I have something like this:
complete return a 200 status, and the done function returns JSON data which means operation "LEAD_INBOX_MENU_KONTAKT_WYKONANY" was ended successfully:

    {
  "step2of3": [
    {
      "GetStatusInfoResult": {
        "ImportDate": "2016-03-31T14:10:25",
        "OpenDate": "2016-04-05T15:41:49",
        "TargetContactDate": "2016-01-29T19:35:49",
        "StatusName": "Open Lead",
        "AssignedToDealer": true,
        "TargetOpenDate": "2016-01-29T19:05:49",
        "StatusCode": "OPEN",
        "CloseDate": null,
        "TargetCloseDate": "2016-03-29T18:35:49",
        "StatusDescription": "",
        "ReminderCloseDate": null,
        "AllocationDate": "2016-01-29T18:35:49",
        "ReallocationDate": null,
        "LeadID": 3739260943,
        "ContactDate": "2016-04-06T13:17:19"
      }
    }
  ],
  "step1of3": {
    "UpdateLeadContactedResponse": [
      ""
    ]
  },
  "step3of3": [
    "OK"
  ]
}

So if it's returning data, why is it not calling my 'success' function?

Upvotes: 1

Views: 1063

Answers (1)

Harish Kommuri
Harish Kommuri

Reputation: 2864

First correct the key of ajax success. You used succes. You have to replace with success. and use success callback as succes_function();. You just specified succes_function;.

Upvotes: 2

Related Questions