.ajax success function with two parameters?
So, I have a function that looks something like this:
function getUnits(squad_id)
{
$.ajax({
type: "GET",
url: ".开发者_如何学Go./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)
How about this:
function getUnits(squad_id) {
$.ajax({
type: "GET",
url: "../XML/unit.xml",
dataType: "xml",
success: function(xml) {
fillSelectUnit(xml, squad_id);
}
});
}
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);
}
});
}
精彩评论