kawa
kawa

Reputation: 65

AJAX Call does not pass success or error

I've got something I don't understand why it's not working. It's making me go crazy.

I've got an AJAX call which does not pass success or error.

function getStraatnamen(woonplaatsId) {
    var success = "not set";
    $.ajax({
        url: someURL,
        type: "POST",
        dataType: 'json',
        contentType: 'application/json',
        async: false,
        xhrFields: {
            withCredentials: true
        },
        data: JSON.stringify({"woonplaatsId": woonplaatsId}),
        succes: function (results) {
            success = "true";
            var straatnamen = results.GetStraatNamenResult;
            var StraatNamenArray = [];
            for (var i = 0; i < straatnamen.length; i++) {
                var straatnaam = straatnamen[i];
                StraatNamenArray.push({ text: straatnaam.naamField, value: straatnaam.idField });
            }
            console.log(StraatNamenArray);
            straatnamenCombobox.setDataSource(StraatNamenArray);
            straatnamenCombobox.bind("change", change_straatnaam);

        },
        error: function (error) {
            success = "false";
            console.log(error);
        }
    });
    alert(success);
}

So when this function starts, I set a succes var to "not set". I've set the request async to false so the variable can be changed during success or error. I've got some console.log for success and error.

But it does not pass any of them, no logs, and the alert shows "not set".

If I look in the browsers network list and in Fiddler, I see the complete result, so the ajax call is made successfully, but it doesn't pass the success or error.

Does any one know why this thing is weird?

Thanx.

Upvotes: 0

Views: 226

Answers (2)

Vladimir Tagai
Vladimir Tagai

Reputation: 331

Your script probably works, but you got a misprint. field "success", two 'S' at the end. :)

Upvotes: 0

mickzer
mickzer

Reputation: 6338

You've spelt "success" as "succes" in your JQUERY.

Change the line

 succes: function (results) {

to

 success: function (results) {

Upvotes: 1

Related Questions