I need to store a value of json response to use in another function.
I have this code:
const url_moodle = "https://xxxxx/xxxxx/app/appmoodlejson.php";
var moodleEmail = function (email){
$.post( url_moodle, { "email":email, "postvar":"email" }, "json")
.done(function( data, textStatus, jqXHR ) {
if(data.data){
// console.log(data.data.id_mdl);
return data.data.id_mdl;
}
})
.fail(function( jqXHR, textStatus, errorThrown ) {
toastr.error('Error, contact support');
if ( console && console.log ) {
console.log( "Fail response: " + textStatus);
}
});
};
var id_mdl = moodleEmail('[email protected]');
If I go to browser console use console.log, data.data.id_mdl show correctly value, but if I use "return" to store value, code no show any error and no function.
Please helpe with any idea to resolve this.