0

I'm sending an AJAX call and retrieving data, which will be simple strings. On a successful call I process these strings into an array and return them. Elsewhere in my app, in a function we'll call "someOtherFunction" I invoke the function that does all this and store the result in a variable. But I'm unable to work with the array this variable contains. In Chromium dev tools, the value logged to the console looks like [equals: function] instead of, what I want ["foo", "bar", "bar bar", "Hello World"]. When I check the length of the variable it always returns as 0, instead of 4.

What I'm aiming to do is invoke the ajaxCall function several times, combine the arrays into an array of arrays, then use the Underscore.js _.intersection method to return an array containing values common to all those arrays. But when the arrays being produced are just [equals: function] with a length of ostensibly 0 I can't do this.

What does this mean, [equals: function] and why is this happening?

ajaxCall: function(){

var leData = [dummyData1: 010101, dummyData2:1010];
var array;

     $.ajax({
       url: '/foobar',
       data: leData,
       success: function(response){
           for(var i = 0; i < response.length; i++){
              if([conditions]){
                array.push(response[i]);
              } 
           }
       });

       return array;
}

someOtherFunction: function(){
   var dataFromAjax = this.ajaxCall();
   //console.log throws back [equals: function] instead of array with strings.
}

0 Answers0