using jquery $.ajax to retrieve data and push data into javascript array through the success functio

Posted by teamdane on Stack Overflow See other posts from Stack Overflow or by teamdane
Published on 2010-05-13T17:34:06Z Indexed on 2010/05/14 9:34 UTC
Read the original article Hit count: 186

Filed under:

Hello All,

I have a function that I'm trying to retrieve values using $.ajax and push the returned data into an array called output. Problem is the success function will not allow me to push the results into the array. see below for code.

              var getValues = function(el)
                         {
                            var value = ($(el).val());

                            if(value == '' || $(el).attr('disabled'))
                            {
                                return [];
                            }

                            var string = 'value=' + value;

                            var output = [];

                            $.ajax({
                              type: "GET",
                              url: 'shocklookup_callback.php',
                              dataType: "string",
                              data: string,
                              success: function(data) {

                                }
                            });


                            //output.push({ text : value + 'test', value : value + 'test1'} );
                            return output;

                        };

Any ideas of what I can put in the success function to be able to push the data into the output array? Also I need to be able to return the output array to the original function getValues.

If this doesn't' make a whole lot of sense please let me know and I'll try to explain better.

Thanks,

  • Dane

© Stack Overflow or respective owner

Related posts about jQuery