I guess I am missing something quite fundamental and maybe someone can fill me in. I have used an ajax call from two places. So now I am trying to reuse that call by making the call return a value. It looks something like this:
function getInfo()
{
$.ajax({
type: "GET",
url: "../ajax.aspx?action=getInfo&id=4",
dataType: "xml",
async: false,
error: function() {
alert("Something went wrong.");
},
success: function(xml) {
// Do some extra work here
$(xml).find("room").each(function() {
// Do something based on the xml
});
// Something else can use this XML so return it too.
// Why does this return not work???
return xml;
}
});
}
So somewhere else in the script i am calling that function
var xml = getInfo();
// Try do something with it now but it says that it is undefined
and when i say it says it is undefined I am talking about Firebug.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…