I got a syntax error on the following code. Once I took out the first line of code, the alert pops. My brain is almost dead and I can’t find out why. Please help. Thanks a lot.
JS
var rss = <?php echo json_encode($test); ?>;
alert("Hello World");
Updated
html
<?php
$test=get_array();
//the $test is a multi-dimention array.
?>
<script type="text/javascript" src="js/slideshow.js"></script>
json_encodewill return FALSE on failure, so if it fails,echo falsewill output nothing.so your code became below, which give you a syntax error.
Edit:
From your updated edit, the reason is:
You can not write php code in a js file.
If you need that variable in the js file, assign it to a global variable first.