Frage

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.

War es hilfreich?

Lösung

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
});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top