$.get() isn't synchronous, the "return" will occur before the request has finished.
You could give this a try, instead: function LerXML(ordem) { var diretorio; $.ajax({ type: "GET", url: "../modulos.xml", async: false, success: function(xmldataset){ diretorio = $("diretorio:eq(" + ordem + ")" , xmldataset); } }); return diretorio.text(); } alert(LerXML(0)); More info: http://docs.jquery.com/Ajax Of course, synchronous XML requests can slow down your application - so it would, most likely, be preferred to write your code using a callback, instead. More info: http://docs.jquery.com/How_jQuery_Works#Callbacks.2C_Functions.2C_and_.27this.27 --John On 3/6/07, Harlley Roberto <[EMAIL PROTECTED]> wrote: > Guys, > > Does someone know why my function doesn't work ? How does work the scope on > JQuery with ajax? > The commented alert is working fine. > > function LerXML(ordem) { > var diretorio; > $.get("../modulos.xml", function(xmldataset){ > diretorio = $("diretorio:eq(" + ordem + ")" , xmldataset); > //alert(diretorio.text()); > }); > return diretorio.text(); > } > alert(LerXML(0)); > > -- > []'s > > Harlley R. Oliveira > www.syssolution.com.br > ------------------------------------------- > ~ U never try U'll never learn ~ > ------------------------------------------- > > > _______________________________________________ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > > _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/