Data retrieval error in Jquery

Posted by Ben on Stack Overflow See other posts from Stack Overflow or by Ben
Published on 2010-06-11T03:08:06Z Indexed on 2010/06/11 3:12 UTC
Read the original article Hit count: 293

I'm trying to retrieve data from a php file named return that contains <?php echo 'here is a string'; ?>. I'm doing this through an html file containing ` div { color:blue; } span { color:red; }

var x; $.get("return.php", function(data){ x = data; }) function showAlert() {alert(x);} $(document).ready(function(){ alert(x); });

` When the button is clicked it retrieves and displays the code fine, but on the page loading, it displays "undefined" instead of the data in return.php. Any solutions?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery