0

I want to return the following response from my jquery code.

function count_waiting(){   
    $.ajax({                                                    
      url: 'index.php/event/count_waiting/2',                           
      type: "post", 
      success: function(response) {         
       return response;     
      } 
    });

}   

By doing this the return is undifned

$(document).ready(function() {
  alert(count_waiting());
});

any idea whats wrong with my code

Praveen
  • 55,303
  • 33
  • 133
  • 164
Markie Mark
  • 129
  • 6
  • 12

1 Answers1

0

an ajax request is async . when you call you count_waiting function, probably your request has not been processed and the result is not yet ready.

When the success callback is fired, your data is ready; call a function(with the result as argument) inside of it or use your data directly here.

diegocstn
  • 4,447
  • 2
  • 20
  • 17