Skip to content

Instantly share code, notes, and snippets.

@nncl
Last active October 15, 2015 22:28
Show Gist options
  • Save nncl/985b9189fe7baebd69f3 to your computer and use it in GitHub Desktop.
Save nncl/985b9189fe7baebd69f3 to your computer and use it in GitHub Desktop.
Getting a PHP variable with jQuery

#PHP Varible to JS

On your .php file, for example:

$var = 'My PHP variable';
echo $var;

And in our .js file we'll make a POST to get the data from PHP:

$.post('file.php', function(data) {
  alert( data );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment