-1

Possible Duplicate:
Echo PHP variable from JavaScript?
How can I get a PHP variable to AJAX?

I'm trying to get some data from my database with php, and put it in a javascript variable. what is the easiest way to do that using JQuery ?

4
  • 3
    Has the page already loaded or are you doing this before the first page load? Commented Dec 4, 2012 at 20:04
  • Is this a question or just a collection of jargon? Commented Dec 4, 2012 at 20:06
  • 1
    no, after the page load. Commented Dec 4, 2012 at 20:06
  • Either way it is a duplicate. Commented Dec 4, 2012 at 20:07

1 Answer 1

0

This is easiest for me, where $var is your array in PHP, being set to the variable "a" in Javascript:

<script type="text/javascript">
var a = <?php echo json_encode($var); ?>;

</script>
Sign up to request clarification or add additional context in comments.

2 Comments

and $var is declared where ? should I include the php file ??
$var is your PHP array you wish to get into javascript. couldn't hurt to include php.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.