Moein Hosseini
Moein Hosseini

Reputation: 4383

How to set JavaScript variable by php with out AJAX?

I need to set JavaScript variable by php variable with out ajax. I try following code:

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

but it will make problem,How can I do it?

Upvotes: 1

Views: 7152

Answers (1)

zerkms
zerkms

Reputation: 254926

Url is a string, so put it within quotes:

var url = '<?php echo($url); ?>';

Upvotes: 14

Related Questions