View Single Post
Old 10-08-2012, 04:05 PM   PM User | #1
erebus
New Coder

 
Join Date: Sep 2012
Location: Houston, TX
Posts: 22
Thanks: 2
Thanked 0 Times in 0 Posts
erebus is an unknown quantity at this point
JavaScript include difficulties

I have small peice of code that runs at the end of my code after the page is created and it manipulates the sidebar which is apart of the overall template. Since its accessing an API i could foresee future changes that would need to be made to the code and ofcourse that needs to be reflected to all pages. So i took my peice of code

Code:
<!-- Top 3 Streams -->
<script type="text/javascript">

var myurl = encodeURIComponent("https://api.twitch.tv/kraken/streams?game=DayZ&limit=3")

scr = document.createElement("script");
scr.type = "text/javascript"
scr.src = 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20json%20where%20url%3D%22' + myurl + '%2F%22&format=json&callback=showGame';
document.body.appendChild(scr);
</script>
<!-- / Top 3 Streams -->
and replaced it with an include

Code:
<!-- Top 3 Streams -->

    <?php include('includes/top3streams.php'); ?>

<!-- / Top 3 Streams -->
and now its not working properly... did i not implement this include properly?

The contents of the include file read

Code:
<script type="text/javascript">

var myurl = encodeURIComponent("https://api.twitch.tv/kraken/streams?game=DayZ&limit=3")

scr = document.createElement("script");
scr.type = "text/javascript"
scr.src = 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20json%20where%20url%3D%22' + myurl + '%2F%22&format=json&callback=showGame';
document.body.appendChild(scr);
</script>
perhaps the <script type="text/javascript"> and </script> needs to remain in the HTML? perhaps its not loading in fast enough? any thoughts?

perhaps i should be using a External JS file instead? or heck, maybe even a more basic HTML include?
erebus is offline   Reply With Quote