User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 422,902 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,270 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1076 | Replies: 2
Reply
Join Date: Jun 2006
Location: College Station, TX
Posts: 35
Reputation: gil857 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
gil857's Avatar
gil857 gil857 is offline Offline
Light Poster

AJAX rss not working in firefox

  #1  
Jun 6th, 2008
I am trying to use ajax to display an rss feed. It works fine in IE, but does not work in firefox. Researching, I have heard that firefox has an error that occurs on an asynchronous ajax call. Does anyone know a work around for firefox. Any help much appreciated.

  1. <body>
  2.  
  3. <script language="javascript" type="text/javascript">
  4.  
  5. var xmlHttp;
  6. try
  7. {
  8. xmlHttp=new XMLHttpRequest();
  9. }
  10. catch (e)
  11. {
  12. try
  13. {
  14. xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  15. }
  16. catch (e)
  17. {
  18. try
  19. {
  20. xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  21. }
  22. catch (e)
  23. {
  24. alert("No AJAX support!");
  25. }
  26. }
  27. }
  28.  
  29.  
  30. xmlHttp.onreadystatechange=function()
  31. {
  32. if(xmlHttp.readyState==4)
  33. {
  34. var rss_response=xmlHttp.responseText;
  35.  
  36. try
  37. {
  38. xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  39. xmlDoc.async="false";
  40. xmlDoc.loadXML(rss_response);
  41. }
  42. catch(e)
  43. {
  44. try
  45. {
  46. parser=new DOMParser();
  47. xmlDoc=parser.parseFromString(rss_response,"text/xml");
  48.  
  49. }
  50. catch(e)
  51. {
  52. alert(e.message);
  53. }
  54. }
  55.  
  56.  
  57. for (loop=1; loop<=10; loop++)
  58. {
  59. document.write("<p><a href=\"" + xmlDoc.getElementsByTagName("link")[loop].childNodes[0].nodeValue + "\">")
  60. document.write(xmlDoc.getElementsByTagName("title")[loop].childNodes[0].nodeValue)
  61. document.writeln("</a><br>");
  62. document.writeln(xmlDoc.getElementsByTagName("description")[loop].childNodes[0].nodeValue + "</p>");
  63. }
  64.  
  65. }
  66. }
  67. var url = "http://www.kbtx.com/home/headlines/index.rss"
  68. xmlHttp.open("GET",url,true);
  69. xmlHttp.send(null);
  70.  
  71.  
  72. </script>
  73.  
  74. </body>


Thanks,

Gil
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2005
Location: New York state
Posts: 464
Reputation: ShawnCplus will become famous soon enough ShawnCplus will become famous soon enough 
Rep Power: 5
Solved Threads: 72
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: AJAX rss not working in firefox

  #2  
Jun 6th, 2008
It's not a Firefox bug its that you're only coding for IE. Use this to get your request object
  1. var XMLHttpFactories = [
  2. function () {return new XMLHttpRequest()},
  3. function () {return new ActiveXObject("Msxml2.XMLHTTP")},
  4. function () {return new ActiveXObject("Msxml3.XMLHTTP")},
  5. function () {return new ActiveXObject("Microsoft.XMLHTTP")}
  6. ];
  7.  
  8. function createXMLHTTPObject() {
  9. var xmlhttp = false;
  10. for (var i=0;i<XMLHttpFactories.length;i++) {
  11. try {
  12. xmlhttp = XMLHttpFactories[i]();
  13. }
  14. catch (e) {
  15. continue;
  16. }
  17. break;
  18. }
  19. return xmlhttp;
  20. }
Then just
  1. var xmlHttp = createXMLHTTPObject();
GCS d- s+:+ a-->? C++(++++) UL+++ P+>+++ L+++ !E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
Reply With Quote  
Join Date: Jun 2006
Location: College Station, TX
Posts: 35
Reputation: gil857 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
gil857's Avatar
gil857 gil857 is offline Offline
Light Poster

Re: AJAX rss not working in firefox

  #3  
Jun 6th, 2008
Thanks for your answer. However, I've run some tests and it does create the request object in firefox.

This statement creates the firefox obj: xmlHttp=new XMLHttpRequest();

The problem is on the readystate function call. Firefox will not call the function.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 1:14 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC