Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript works great locally, but not on my server
    primarykey
    data
    text
    <p>I'm teaching myself javascript by creating a script for displaying an external rss feed on a webpage. </p> <p>The code I patched together works great locally. This is a screen grab of the code producing exactly the desired behavior. The code is populating all the information inside the section "Blog: Shades of Gray", except for "tagged" which I hard coded:</p> <p><img src="https://i.stack.imgur.com/xP7ad.png" alt="http://screencast.com/t/fNO5OPnmGPm2"></p> <p>But when I upload the site files to my server, the code doesn't work at all. This is a screen grab of the code on my site NOT producing the desired behavior... </p> <p><img src="https://i.stack.imgur.com/6yucm.png" alt="alt text"></p> <p>This feels like I'm not getting something really basic about how javascript works locally vs. on the server. I did my half hour of googling for an answer and no trails look promising. So I'd really appreciate your help.</p> <p>This is my site (under construction) <a href="http://jonathangcohen.com" rel="nofollow noreferrer">http://jonathangcohen.com</a></p> <p>Below is the code, which can also be found at <a href="http://jonathangcohen.com/grabFeeds.js" rel="nofollow noreferrer">http://jonathangcohen.com/grabFeeds.js</a>.</p> <pre><code>/*Javascript for Displaying an External RSS Feed on a Webpage Wrote some code that’ll grab attributes from an rss feed and assign IDs for displaying on a webpage. The code references my Tumblr blog but it’ll extend to any RSS feed.*/ window.onload = writeRSS; function writeRSS(){ writeBlog(); } function writeBlog(){ if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","http://blog.jonathangcohen.com/rss.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; var x=xmlDoc.getElementsByTagName("item"); //append category to link for (i=0;i&lt;3;i++) { if (i == 0){ //print category var blogTumblrCategory = x[i].getElementsByTagName("category")[0].childNodes[0].nodeValue document.getElementById("getBlogCategory1").innerHTML = '&lt;a class="BlogTitleLinkStyle" href="http://blog.jonathangcohen.com/tagged/'+blogTumblrCategory+'"&gt;'+blogTumblrCategory+'&lt;/a&gt;'; //print date var k = x[i].getElementsByTagName("pubDate")[0].childNodes[0].nodeValue thisDate = new Date(); thisDate = formatTumblrDate(k); document.getElementById("getBlogPublishDate1").innerHTML = thisDate; //print title var blogTumblrTitle = x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue var blogTumblrLink = x[i].getElementsByTagName("link")[0].childNodes[0].nodeValue document.getElementById("getBlogTitle1").innerHTML = '&lt;a class="BlogTitleLinkStyle" href="'+blogTumblrLink+'"&gt;'+blogTumblrTitle+'&lt;/a&gt;'; } if (i == 1){ //print category var blogTumblrCategory = x[i].getElementsByTagName("category")[0].childNodes[0].nodeValue document.getElementById("getBlogCategory2").innerHTML = '&lt;a class="BlogTitleLinkStyle" href="http://blog.jonathangcohen.com/tagged/'+blogTumblrCategory+'"&gt;'+blogTumblrCategory+'&lt;/a&gt;'; //print date var k = x[i].getElementsByTagName("pubDate")[0].childNodes[0].nodeValue thisDate = new Date(); thisDate = formatTumblrDate(k); document.getElementById("getBlogPublishDate2").innerHTML = thisDate; //print title var blogTumblrTitle = x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue var blogTumblrLink = x[i].getElementsByTagName("link")[0].childNodes[0].nodeValue document.getElementById("getBlogTitle2").innerHTML = '&lt;a class="BlogTitleLinkStyle" href="'+blogTumblrLink+'"&gt;'+blogTumblrTitle+'&lt;/a&gt;'; } if (i == 2){ //print category var blogTumblrCategory = x[i].getElementsByTagName("category")[0].childNodes[0].nodeValue document.getElementById("getBlogCategory3").innerHTML = '&lt;a class="BlogTitleLinkStyle" href="http://blog.jonathangcohen.com/tagged/'+blogTumblrCategory+'"&gt;'+blogTumblrCategory+'&lt;/a&gt;'; //print date var k = x[i].getElementsByTagName("pubDate")[0].childNodes[0].nodeValue thisDate = new Date(); thisDate = formatTumblrDate(k); document.getElementById("getBlogPublishDate3").innerHTML = thisDate; //print title var blogTumblrTitle = x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue var blogTumblrLink = x[i].getElementsByTagName("link")[0].childNodes[0].nodeValue document.getElementById("getBlogTitle3").innerHTML = '&lt;a class="BlogTitleLinkStyle" href="'+blogTumblrLink+'"&gt;'+blogTumblrTitle+'&lt;/a&gt;'; } } } function formatTumblrDate(k){ d = new Date(k); var curr_date = d.getDate(); var curr_month = d.getMonth(); curr_month++; var curr_year = d.getFullYear(); printDate = (curr_month + "/" + curr_date + "/" + curr_year); return printDate; } </code></pre> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload