Question

I'm trying to use a php code snippet for jQuery Cycle Slideshow, but the console gives me this error:

"Uncaught SyntaxError: Unexpected token < "

var startingSlide = <?php echo $_GET["thumb"] ?>;

$(slideshowContainer).cycle ({
    startingSlide: startingSlide
});

How can I use the PHP code correctly?

I'd appreciate you help.

Était-ce utile?

La solution

PHP doesn't parse files with a .js ending, but you could have the PHP parser parse javascript files, but that's a really bad idea, instead insert the PHP in the PHP file where it belongs, and get the data with javascript

<div id="some_element" data-startingslide="<?php echo $_GET["thumb"] ?>"></div>

then do

var startingSlide = $('#some_element').data('startingslide')

$(slideshowContainer).cycle ({
    startingSlide: startingSlide
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top