0
$.get("test.php",function(result){
  var data = result;
});
alert(data);

test.php do one thing only
<? echo "ABC"; ?>
this script always return 'ReferenceError: data is not defined' error
i tried to declare var data=""; before $.get but the value of data did not changed after $.get. this method can works in common function.
i also tried to use window.data=result to made data global but nothing changed.
what is wrong?

wskdpw
  • 27
  • 2
  • `var data; $.get("test.php",function(result){ data = result; });` But this will alert `undefined` – Tushar Oct 20 '15 at 03:57
  • @tushar with this logic of creating duplicated question, then we should close stackoverflow and redirect all to document of programming language. the question that you think is like this one have less than %40 common with this question. – Omidam81 Oct 20 '15 at 04:03
  • @Omidam81 The question http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-asynchronous-call is same as this and any of the answer on it will help to solve this problem – Tushar Oct 20 '15 at 04:04
  • var data=' '; $.get("test.php",function(result){ data = result; }); alert(data); – Hussy Borad Oct 20 '15 at 04:49
  • I see....Thank You ! – wskdpw Oct 20 '15 at 07:00

0 Answers0