troubleshooting Question

javascript function return problem

Avatar of Marco Gasi
Marco GasiFlag for Spain asked on
JavaScriptjQueryAJAXJSON
15 Comments2 Solutions196 ViewsLast Modified:
Hi all.
I have a probably stupid problem I can' sove by myself :-(
I have this function which returns a number:
function getFolderCardsNumber(folder) {
	jQuery.ajax({
		type: 'post',
		url: 'script.php',
		data: {folder: folder},
		success: function (result)
		{
			var response = JSON.parse(result);
			console.log('in folder ' + folder + ' there are '+response + ' cards');
			return response;
		},
		error: function (result)
		{
			console.log('error');
		}
	});
}
The value in console is correct, so it looks to work fine. But here  I get undefined!
jQuery(document).ready(function ()
{
	var pc_cards_number, sp_cards_number;
	pc_cards_number = getFolderCardsNumber('PC');
	console.log('inner PC is '+pc_cards_number);
	sp_cards_number = getFolderCardsNumber('SP');
	console.log('inner SP is '+sp_cards_number);
});
Thnk you so mutch.
ASKER CERTIFIED SOLUTION
Alexandre Simões
Software Architect

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 15 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 15 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros