Reputation: 3
unexpected token '<'
testing it on a blank html page works, moving it to a wordpress theme fails.
the getimg.php returns the array correctly
$('body').backfade([<?php include'../inc/getimg.php' echo '"'.implode('", "', $image_files).'"' ?>]);
Upvotes: 0
Views: 63
Reputation: 163291
Don't inject data into JavaScript this way. Use json_encode()
.
var image_files = <?php echo json_encode($image_files) ?>; // Outputs ['file1', 'file2', etc.]
$('body').backfade(image_files);
Without it, you are missing the escaping needed to interpret your data correctly, and opening up yourself to potential security issues.
Upvotes: 1