I am new to JavaScript and trying to learn more about programming in general. I have taken a VERY basic JavaScript class in college but learned very little. I have looked at some code examples from various sources on the Internet and diagrammed the logic in an attempt to learn. I have tried to make changes to the code in an attempt to learn more by making the functions more generic so they could handle more than one request.
Here is the code example that I discovered on the Internet and have modified in an attempt to learn more from.
Code:<script language="javascript" type="text/javascript"> // Variable which holds the rss feed. This will have to be modified once I get the // correct logic working Backend = 'http://www.atomicrod.info/detroitsportsthatmatter/index.php?/feeds/index.rss1'; // Function to create the xmlhttp request function RSSRequestObject() { if (window.XMLHttpRequest) return new XMLHttpRequest(); if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP"); } // Function which will taket he xmlhttp request and send it. Sets the state change // Event handler function RSSRequest(SectionRequest) { HideShow('status'); document.getElementById("status").innerHTML = "Requesting data ..."; SectionRequest.open("GET", Backend, true); SectionRequest.send(null); if (SectionRequest.onreadystatechange) ReqChange(SectionRequest); //RSSRequestObject = false; } // Function which trips when Event Handler fires and passes the request object function ReqChange(RequestObject) { if (RequestObject.readyState==4) { if (RequestObject.responseText.indexOf('invalid') == -1) { var node = RequestObject.responseXML.documentElement; var channel = node.getElementsByTagName('channel').item(0); var title = channel.getElementsByTagName('title').item(0).firstChild.data; var link = channel.getElementsByTagName('link').item(0).firstChild.data; content = '<div class="channeltitle"><a href="'+link+'">'+title+'</a></div><ul>'; var items = channel.getElementsByTagName('item'); for (var n=0; n < items.length; n++) { var itemTitle = items[n].getElementsByTagName('title').item(0).firstChild.data; var itemLink = items[n].getElementsByTagName('link').item(0).firstChild.data; content += '<li></font><a href="'+itemLink+'">'+itemTitle+'</a></li>'; } content += '</ul>'; document.getElementById("ajaxreader").innerHTML = content; document.getElementById("status").innerHTML = "Done."; } else { document.getElementById("status").innerHTML = "<div class=error>Error requesting data.<div>"; } } } function RSSFeeds() { Sports() Politics() MainSite() OffSite() } function Sports() { var RSSSports = RSSRequestObject(); RSSRequest(RSSSports); }
I beleive the problem is this line of code:
if (SectionRequest.onreadystatechange) ReqChange(SectionRequest);
I am not sure if I'm using the event handler proplery or the fact that I'm taking a variable created in one function and passing it to another is causing the problem.
What happens with the code is I get requesting data, but it never receives the feed back.
If anyone can be of any help on what logical/language mistakes I've made I'd appriciate it.
Thanks for the help.




Bookmarks