you can't return a value from an anonymous function!

think about it: you call $.get() and pass in an anon function as a
parameter.

$.get() returns basically immediately, and then sometime later (much
later) your anon function will be called.

Where does the return value of anon go? Nowhere.

That's why you have to either process the result of your ajax call in
the anon method you pass in. (You can also stick the results in a
variable to be processed later, but that's a bit messier.)

-j

On Feb 12, 10:04 pm, jquertil <[EMAIL PROTECTED]> wrote:
> Hi,
> I'm mixing regular javascript with Jquery and for some reason I cannot
> pass a return value back - any idea why?
>
> output = loadXMLarray('echo.php','datatable1') );
> alert (output); // does not work
>
> function loadXMLarray(scripturl,variable){
>         $.get(scripturl,{xml:variable}, function(data){ // loading my XML
>         objectArray = new Array(); // setting up my array to hold objects
> with
>                 $(data).find('row').each(function(i){ // iterating through my 
> XML
> source
>                         rowObj = new Object(); // adding attributes to my 
> object
>                         rowObj.col1 = $(this).children('col_1').text();
>                         rowObj.col2 = $(this).children('col_2').text();
>                         rowObj.col3 = $(this).children('col_3').text();
>                 objectArray.push(rowObj); // populating my array
>                 });
>         alert(objectArray); // this works
>         return objectArray; // does not work
>         });
>         return objectArray; // tried it here as well but that returns nothing
>
> }

Reply via email to