I have this in my HTML code
<script type="text/javascript">
    var URL = replace(); 
    alert(URL);
</script>
If I put this in header, alert shows “http://example.com/result"
function replace() { 
 url = 'http://example.com'; 
 $.get(url, function(data){ 
  var url_gen = data.responseText; 
 }); 
 return “http://example.com/result"; 
} 
But if I use return like this, it won't do anything. Why?
function replace() { 
 url = 'http://example.com'; 
 $.get(url, function(data){ 
  var url_gen = data.responseText; 
 }); 
 return url_gen; 
} 
Just to make sure, If I insert alert(url_gen) in front of return url_gen; in 2nd code, alert shows 'http://example.com' so url_gen has an actual value in it!
Note: Here, assuming that url_gen is the string which is web-scraped from a web page.
 
     
     
    