omega omega - 2 months ago 14
Ajax Question

How to add more parameters to jquery ajax success and error functions

In a jquery ajax success/error function like this:

success:

function (data, textStatus, jqXHR) {

}


error:

function (jqxr, errorCode, errorThrown) {

}


Is there a way, I can pass an array of values like this
[A,B,C]
to the ajax function, and then have it come back as

success:

function (data, textStatus, jqXHR, A, B, C) {

}


error:

function (jqxr, errorCode, errorThrown, A, B, C) {

}


Thanks

Answer

You must apply those variables outside the ajax call or you can use "context:" to pass the context which you will have those variables. What you are demonstrating above is not applicable.

UPDATE -

var data = ["a", "b"];
    $.ajax({
        type: "GET",
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        url: "/s",
        context: data,
        data: data
    }).done(function (result) {
        console.log(this);
    }).error(function (r) {
        console.log(this);
    });
Comments