Below is my code:
<script src="jquery-1.8.3.js" type="text/javascript">
</script>
<script type="text/javascript">
var obj=[] ;
function getData(){
$.ajax({
url:'jqueryJsonTest.php',
type:'POST',
dataType: 'json',
cache: true,
success:function(data){
obj = data ;
alert ("alert 1: "+obj.length);
}
});
}
$(document).ready(function() {
getData();
alert("alert 2: "+obj.length);
alert("alert 3: "+obj.length);
});
</script>
Why is the first result after saving data an empty array?