I was wondering are there any restrictions regarding sharing global variables between two scripts if I set the value by a $.get approach?
My code of script 1:
<script type="text/javascript">
var get_data;
$.get('website_url', function(data) {
get_data = "show me the data";
console.log("1", get_data);
});
console.log("2", get_data);
</script>
My code in script 2:
<script type="text/javascript">
console.log("3", get_data)
</script>
The output of my console.logs
are as follows:
- 2 undefined
- 3 undefined
- 1 show me the data
I do not understand why the global variable is not filled with the "show me the data" string. Can anyone help me or tell me why this does not work?