Possible Duplicate:
How to return a value from a function that calls $.getJSON?
This seems very basic, but I can't figure out what is happening. I am using Firebug, but I'm not getting any errors when I run the script.
Here is my JS function:
function getMainContactCount()
{
$.getJSON('<?php echo site_url('get_leads/main_contact'); ?>',
function(data) {
return data.length;
}
);
}
If I set a variable equal to this function like var x = getMainContactCount(), I get nothing. Yet, I can console.log the value of data.length and it returns the correct value. What am I doing wrong? I also tried setting a variable equal to data.length in the anonymous function and then returning it below the JSON call, but that didn't work either.