I found a similar topic where the user gave a reply that 'window' name is needed before the variable name. But it doesn't seem to work for me.
Could someone help me understand why window.data_from_ajax
printed in console.log() is undefined?
PHP
<?php
echo 'php_data';
?>
Javascript
window.data_from_ajax;
$.get('java_test.php', function(data) {
window.data_from_ajax = data;
alert(data);
});
console.log('data_from_ajax='+window.data_from_ajax);