Pillblast
Pillblast

Reputation: 1221

.ajax success function with two parameters?

So, I have a function that looks something like this:

function getUnits(squad_id)
{
$.ajax({
type: "GET",
url: "../XML/unit.xml",
dataType: "xml",
success: fillSelectUnit(xml,squad_id)
});
}

and the function

fillSelectUnit(xml,id)
{
alert (id);
}

Obviously, it's not working...

For the life of me I can't manage to transmit the parameter to the second function. Anyone knows how to do that? I simply can't find anywhere (I am using jQuery)

Upvotes: 2

Views: 7786

Answers (2)

peakit
peakit

Reputation: 29359

Check this jQuery page. This explains how to specify callbacks that need arguments.

In short you can re-write the method as:

function getUnits(squad_id)
{
$.ajax({
    type: "GET",
    url: "../XML/unit.xml",
    dataType: "xml",
    success: function(xml) {
        alert(squad_id);
    }
  });
}

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1038820

How about this:

function getUnits(squad_id) {
    $.ajax({
        type: "GET",
        url: "../XML/unit.xml",
        dataType: "xml",
        success: function(xml) {
            fillSelectUnit(xml, squad_id);
        }
    });
}

Upvotes: 7

Related Questions