简体   繁体   中英

Pass a variable from a get query in javascript

I am trying to pass the value of a parameter outside a $.get jQuery in javascript. I read that I should somehow do that in synchronous mode but I couldn't find a solution.

Here is my code:

var flag;
var t = $.get("mutalyzer.php?id="+variation.value, function(data) {
    flag=data;
});
document.write(flag);

where I get undefined as a result.

Thanks!

write it inside the callback function

try this

var t = $.get("mutalyzer.php?id="+variation.value, function(data) {
   //this is the callback function and runs when get gets  completed
   flag=data;
   document.write(flag); 
 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM