Trying to run a script, (test.al();) and inside test.al, its called getcrypt.php();, the php script is on a webserver, and it is working. Currently, these are my scripts
JS
var getcrypt = {
    php: function () {
        $.ajax({
            url: "server.com/return.php",
            type: "POST",
            async: true,
            data: "id=getit",
            success: function (msg) {
                var v = msg.match(/^.*$/m)[0];
                return v;
            }
        });
    }
}
var test = {
    al: function () {
        a = getcrypt.php();
        alert(a);
    }
}
PHP
<?php
    $id = $_POST['id'];
    if ('getit' == $id){
        $value = 'VALUE';
        echo $value;
    }else{
        echo 0;
    }
?>
In this way, it will show an alert with 'unidefined', and if i add a alert(v); right before return v, it will show me 'VALUE', but not able to use it outside the variable...
var getcrypt = {
    php: function () {
        $.ajax({
            url: "server.com/return.php",
            type: "POST",
            async: true,
            data: "id=getit",
            success: function (msg) {
                var v = msg.match(/^.*$/m)[0];
                alert(v);
                return v;
            }
        });
    }
}
This will give me an alert with the correct value (AFTER THE 'undefined')
 
     
     
     
     
    