문제

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.

도움이 되었습니까?

해결책

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
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top