0
<script>  
   var value1;


        $.get("test.php", function(data){
          var mydata= $.parseJSON(data);
          value1 = mydata.value1; 


    });
       console.log(value1);

</script>

in my program the value1 is giving the value in $.get function but when i try to access it outside the get function scope it says undefined

1 Answers1

0

Becasue $.get is an asynchronus call. You fire $.get method and don't wait for getting response immidiately console.log will be called. if you print console.log in $.get you will get value. Read about asynchronus functions