473,503 Members | 3,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ajax ticker news feed

danielm60
16 New Member
I have a newsfeed which is made up of a js ticker that uses a php grab to convert an rss feed and show it in a html page but I have an error ....

MyElement.getElimentsByTagName(naming)[0].firstChild is null

If I click ok it goes away and the ticker works fine.

Can anyone help me correct the error?
Attached Images
File Type: jpg error 1.jpg (14.2 KB, 1054 views)
May 14 '10 #1
14 2847
gits
5,390 Recognized Expert Moderator Expert
without seeing the code it would be guesswork to give an answer ... basically:

first i assume that:
Expand|Select|Wrap|Line Numbers
  1. MyElement.getElimentsByTagName(naming)[0].firstChild
is a typo it needs to be:
Expand|Select|Wrap|Line Numbers
  1. MyElement.getElementsByTagName(naming)[0].firstChild
in case it was a typo in the post then the above line refers to a node that doesn't exist ... at least at this moment where it should be retrieved ...

kind regards
May 14 '10 #2
danielm60
16 New Member
Hi
here is the js code if it helps

Expand|Select|Wrap|Line Numbers
  1.     function getRequest() {
  2.         var con = new Array();
  3.         var _ms_XMLHttpRequest_ActiveX = "";
  4.         var req;
  5.         if (window.XMLHttpRequest) {
  6.             req = new XMLHttpRequest();
  7.         } else if (window.ActiveXObject) {
  8.             if (_ms_XMLHttpRequest_ActiveX) {
  9.                 req = new ActiveXObject(_ms_XMLHttpRequest_ActiveX);
  10.             } else {
  11.                 var versions = ["Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
  12.                 for (var i = 0; i < versions.length ; i++) {
  13.                     try {
  14.                         req = new ActiveXObject(versions[i]);
  15.                         if (req) {
  16.                             _ms_XMLHttpRequest_ActiveX = versions[i];
  17.                             break;
  18.                         }
  19.                     } catch (objException) {
  20.                                 // trap; try next one
  21.                     }
  22.                 }
  23.             }
  24.         }
  25.         con[0]=req;
  26.         con[1]=_ms_XMLHttpRequest_ActiveX;
  27.         return con;
  28.     }
  29.  
  30.     function loadRSS(url) {
  31.     //alert("running");
  32.         try {
  33.             if ( _ms_XMLHttpRequest_ActiveX1 ) {
  34.                 rssRequest.onreadystatechange = processRSS;
  35.                 rssRequest.open("GET", url, true);
  36.                 rssRequest.send(null);
  37.             } else {
  38.                 if (rssRequest) {
  39.                     rssRequest.onreadystatechange = processRSS;
  40.                     rssRequest.open("GET", url, true);
  41.                     rssRequest.send(null);
  42.                 }
  43.             }
  44.         } catch ( rssRequestException ) {}
  45.     }
  46.  
  47.  
  48.     function getChildNode( myElement, naming ) {
  49.         return myElement.getElementsByTagName(naming)[0].firstChild.nodeValue;
  50.     }
  51.  
  52.     function processRSS() {
  53.         var cycle = 0;
  54.         try {
  55.             if (rssRequest.readyState == 4) {
  56.                 if (rssRequest.status == 200) {
  57.                     response = rssRequest.responseXML.documentElement;
  58.                     if ( response ) {
  59.                         var items = response.getElementsByTagName("item");
  60.                         for ( var i = 0 ; i < items.length; i++ )
  61.                         {
  62.                             var title = getChildNode(items[i],"title");
  63.                             var desc = getChildNode(items[i],"description");
  64.                             var link = getChildNode(items[i],"link");
  65.                             rssItems[cycle] = title + " - " + desc;
  66.                             linkItems[cycle] = link;
  67.                             ++cycle;
  68.                         }
  69.                     }
  70.                 } else {
  71.                     alert("There was a problem retrieving the XML data:\n" + req.statusText);
  72.                 }
  73.             }
  74.         } catch ( jsException ) {alert(jsException.message);}
  75.     }
  76.  
  77.     var httpArc2                         = getRequest();
  78.     var rssRequest                        = httpArc2[0];
  79.     var _ms_XMLHttpRequest_ActiveX1     = httpArc2[1];
  80.  
  81.     var rssItems = new Array();
  82.     var linkItems = new Array();
  83.  
  84.  
  85.     function openWindow(url){
  86.         window.open(url);
  87.     }
  88.  
  89.  
  90.  
  91.     var storyCount = 0;
  92.     var itemLen = 0;
  93.  
  94.     function tickTock(){
  95.  
  96.         var obj = document.getElementById("scroller");
  97.  
  98.         var myTimeout = 50;
  99.         var str;
  100.         var st = rssItems[storyCount];
  101.  
  102.         if ( itemLen > st.length ) {
  103.             storyCount++;
  104.             if ( storyCount >= rssItems.length  ) {
  105.                 storyCount = 0;
  106.             }
  107.             itemLen = 0;
  108.             myTimeout=2000;
  109.             setTimeout("tickTock()", myTimeout);
  110.         } else {
  111.             ++itemLen;
  112.             str = rssItems[storyCount].toString();
  113.             str = str.substring(0,itemLen) + "_";
  114.             obj.innerHTML = "<span class=globalheader>Latest BBC News:</span><br/><a href=\"javascript:openWindow('"+linkItems[storyCount]+"')\" class=headlines>" + str + "</a>";
  115.             setTimeout("tickTock()", myTimeout);
  116.         }
  117.  
  118.     }
  119.  
  120.     setTimeout("tickTock()", 3000);
  121.  
  122.  
  123.     loadRSS("/grab.php?http://news.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml");
May 14 '10 #3
gits
5,390 Recognized Expert Moderator Expert
so as you might see the error probably comes from one of the lines 62, 63 or 64 where the getChildNode()-method is called. since this method is called on the result of the XMLHttpRequest i suspect that the response might miss an item's subnode or that there is a corrupt node somewhere ... so that:

Expand|Select|Wrap|Line Numbers
  1. myElement.getElementsByTagName(naming)
returns null somewhere on that result. probably you have an empty item or similar.

kind regards
May 14 '10 #4
danielm60
16 New Member
Hi sorry Im a newb ... so I dont really know what you are say except that
MyElement.getElementsByTagName(naming)[0].firstChild
means that an element is empty!

Can you help to fix it ?
May 14 '10 #5
gits
5,390 Recognized Expert Moderator Expert
you would need to check the returned XML structure ... the method fails on a specific node ...
May 14 '10 #6
danielm60
16 New Member
Hi

How do it do that as the wole ticker is just the 2 .php. files and the js file ?
See attached

I think the error comes from line 103 of the js file where the lenghth is null or not an object
Attached Files
File Type: zip ticker.zip (2.4 KB, 84 views)
May 16 '10 #7
gits
5,390 Recognized Expert Moderator Expert
just call the app in Firefox with an installed firebug-extension and check the response of the XMLHttpRequest - you might even use Safari and activate the developer tools to check that ... Firebug will then tell you which line would produce the problem.

from you first post it is obvious that the error occurs in the getChildNode()-method ... which is called from the lines 62-64 in post #3. that is why i assume that the response is corrupt somewhere ... so that any item might miss a title, description or link node.
May 16 '10 #8
danielm60
16 New Member
Hi gits,

Yes already done that
The line is 103 as per earlier posts
# if ( itemLen > st.length ) {
# storyCount++;
# if ( storyCount >= rssItems.length ) {
# storyCount = 0;

I just dont know how to cure it or get the browser to ignore the problem as the ticker works fine once you click ok to the error
see
www.ukvine.com
if it helps the rss is
http://news.bbc.co.uk/rss/newsonline...t_page/rss.xml
May 18 '10 #9
gits
5,390 Recognized Expert Moderator Expert
i suspect that the there are more problems ... first ... the two alerts come from the line where you catch the exeption:
Expand|Select|Wrap|Line Numbers
  1. alert(jsException.message);
this is what we already talked about above.

the other error seems to come from line:
Expand|Select|Wrap|Line Numbers
  1. obj.innerHTML = "<span class=globalheader>Latest BBC News:</span><br/><a href=\"javascript:openWindow('"+linkItems[storyCount]+"')\" class=headlines>" + str + "</a>";
as this code isn't executed reliably from the page's onload event i suspect that the code runs to ealy and the DOM isn't ready at this moment ... when it runs the second time it finds the obj ... you might return from that function if
Expand|Select|Wrap|Line Numbers
  1. obj == null
or better you create a defined flow for your code ... you should start all DOM operations after! the document's onload event ...
May 19 '10 #10
danielm60
16 New Member
Oh no ... sounds like a nightmare... it's too much for a newbie like me... is there anyone you can recommend who could fix this for me ?
May 21 '10 #11
gits
5,390 Recognized Expert Moderator Expert
just be sure to start all DOM related operations not before the documents onload event. this is quite simple ... the document's DOM is reliably ready to use when the following event is fired:

Expand|Select|Wrap|Line Numbers
  1. <body onload="alert('Documment DOM ready');">
so you would just need to call your first line of JavaScript from here and go on with the rest.

kind regards
May 22 '10 #12
danielm60
16 New Member
Hey thanks for your help...

So it's just a case of rearranging the existing code code ?

It that in the html or the js ?

What line number would that start at ?
May 22 '10 #13
gits
5,390 Recognized Expert Moderator Expert
as you might see the onload-handler is assigned the the document's body element in the above example. it isn't just rearranging ... it even would involve a bit refactoring. you would need to call everything DOM-realted from a function that is then called when the onload fires ... currently you just include scripts and call functions from there. in case the DOM is not ready you will get errors from all methods that would rely on this ... and as i already said a delay is quite unreliable. so in your included scripts you should ensure that no such method is directly called during the include but later on from the onload-handler ...
May 22 '10 #14
danielm60
16 New Member
Right .... I think this is way above my knowledge base... so it's something I need to get done by a js script code writer... I was just hoping there was a quick fix to the problem
May 22 '10 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1843
by: Cam | last post by:
Hi I'm using this simple rss parser that i would like to have open in another window. But I'm very much a beginner in php scripting. Here is the script on the page <?php ...
4
1774
by: John | last post by:
Hi everyone ! I am a newbie to this newsgroup. I would appreciate if someone can help me to solve this problem. OK, I am currently writing a webpage in PHP that will get RSS file(XML file)...
2
1030
by: Bengt Richter | last post by:
I can see postings on google, but my news service is having a problem since sometime during the weekend. Can get old stuff from other n.g., but no new. Wondering whether I'll see this via google....
1
1277
by: mark | r | last post by:
i want to 'grab' an rss news feed from a public site that has the xml file published on an hourly basis. how do i do this in asp? mark
0
1610
by: Amit Chandel | last post by:
For those people looking to learn on how to start making apps with VB.NET, I *QUICKLY* made this application to stream real-time news from Google News. It definitely gets the job done, and is...
1
2716
by: it hates me | last post by:
Hey gang, I hope you're all well and you're having an enjoyable week I'd love to be able to have a custom news feed on my web page through Javascript The only custom news feed I can find for...
3
1422
by: Mike Owen | last post by:
Does anybody know how I can display a news feed such as: http://p.moreover.com/cgi-local/page?c=Sports%3A%202006%20World%20Cup%20news&o=rss002 and others on my VB.Net web site? Is there any...
2
1285
by: J_Zanetti | last post by:
Hello everybody! Ive created a ticker that reads my RSS files by loading the xml in an Ajax function. To refresh the content, Ive used a settimeout that reloads the xml, through ajax calls, and...
3
1815
by: Steve Thackery | last post by:
My newly installed Visual C# 2008 is failing to show the "Visual C# Developer News". It says: "The current news channel might not be a valid RSS feed, or your internet connection might be...
1
1986
by: Ellie | last post by:
I need to be able to get a feed and then have it displayed on my website. I'm not sure if I can get the feed, but if I can, what would be the best way to create a web page from the feed? Also, if I...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7357
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7012
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
402
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.