I am attempting to use JSON to return an array that I can manipulate and use later, but, something is going wrong when I use AJAX to return a JSON encoded string. I am currently using alerts as a method of debugging, and my alerts appear to fire in the wrong order.
Scripts:
<script type="text/javascript">
jQuery(document).on('change', '#ProductNumbers', function()
{
selectedIndex = $('#ProductNumbers').prop('selectedIndex');
var productNumber = $('#ProductNumbers').val();
var jArray = getCategories( productNumber );
alert( jArray );
});
</script>
<script type="text/javascript">
function getCategories( productNumber )
{
$.ajax({
url: '/php/DBManager/GetCategories.php',
data: {
ProductNumber: productNumber
},
success: function(result)
{
alert( result );
return result;
}
});
}
</script>
The first script calls the second, but the line alert( jArray ); alerts as undefined, and then i get the alert( result ); from the second script, which returns what it should.
Any ideas?