Reloading canvas javascript after ajax call -
scenario: canvas based portfolio items listed ajax driven pagination.
problem: after loading next page of content ajax, script tags aren't inside canvas tags.
tried: adding script tags before canvas tags, isn't loaded either (so problem loading scripts).
research: jquery script not working, apparently can't retrieve scripts because of security.
possible alternative: adding canvas content outside canvas tags, difficulty comes in passing dynamically created portfolio title tags!
code:
<ul id="products-list"> <?php $i = 0; while($the_list->have_posts()): $the_list->the_post(); //wordpress loops through posts ?> <li class="product-item<?php echo $i;?>"> <script>functionformakingacanvasoverlayusingtheposttitle("<?php echo get_the_title() ?>");</script> <canvas></canvas> </li> <?php $i++; ?> <?php endwhile; ?> </ul> 6 items shown per page , next button uses ajax call next 6 items
suggestions? thanks.
myyou can't add javascript code using ajax without calling hated eval method. , in case, don't need to. answer call external javascript on object, rather calling javascript directly. code you've given sparse, idea below purely demonstration purposes - you'll need translate actual situation:
<canvas><div id="mytitle"></div></canvas> <script> function drawtitleoverlay(title){ var titleoverlayhtml = buildtitleoverlayhtmlfromtitle(title); document.getelementbyid('mytitle').innerhtml = titleoverlayhtml; } function nextpage(){ var data = getajaxdata(); var title = gettitlefromdata(data); drawtitleoverlay(title); } </script>
Comments
Post a Comment