The $.get call is AJAX. The first 'A' in Ajax is for 'Asynchronous'. So when
that line is parsed and executed it kicks of a request to the server which
will come back at some later point. The javascript interpreter doesn't sit
around waiting for it to return. It goes right on with the next line of
script. Only when the Ajax get result comes back from the server, your
callback function is executed. It could be executed much later than the
line(s) immediately following the $.get.
- Richard
On Thu, Oct 9, 2008 at 6:46 AM, Flint ZA <[EMAIL PROTECTED]> wrote:
>
> Fantastic! Thank you :)
> Do you mind explaining to me why this works like this?
>
> On Oct 8, 4:29 pm, Rene Veerman <[EMAIL PROTECTED]> wrote:
> > > function UpdateList()
> > > {
> > > // Open the xml file
> > > $.get("locations.xml",{},function(xml){
> > > // Run the function for each name tag in the XML file
> > > $('location',xml).each(function(i) {
> > > alert($(this).find("name").text());
> >
> > > });
> > > alert("Test");
> >
> > > });
> >
> > > }
> >
> > you just needed to put the last alert inside the $.get callback func
>