Quantcast
Channel: Active questions tagged return-value - Stack Overflow
Viewing all articles
Browse latest Browse all 207

Store result of json request in a variable [duplicate]

$
0
0

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('someemail@emailsome.com');

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.


Viewing all articles
Browse latest Browse all 207

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>