Create/access global variable created on AJAX call - Javascript Data Type

Javascript examples for Data Type:Variable Scope

Description

Create/access global variable created on AJAX call

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//  w  ww.  j  av  a 2  s.c o m
var ajax_response='var message="Hello World!";';
var sc=document.createElement('script');
sc.text=ajax_response;
document.body.appendChild(sc);
console.log(message);
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials