error using XmlHttpRequest in Firefox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • satishr23
    New Member
    • Mar 2007
    • 10

    error using XmlHttpRequest in Firefox

    Hi, I am trying to develop a RSS reader using Ajax.
    I use the following Get statement.
    AjaxObject.open ("GET",URL,true )
    where URL is the location of my feed.
    Now when I give URL as a file in my localhost directory, it works fine in both IE and Firefox.
    But when give URL as a remote feed,it doesnt work in Firefox. It gives me an 'undefined' error.
    I read somewhere that it could be because Firefox blocks cross-domain operations so I included the folowing statement in my Js file

    try
    {
    netscape.securi ty.PrivilegeMan ager.enablePriv ilege("Universa lBrowserRead");
    }
    catch(e)
    {
    alert("Permissi on UniversalBrowse rRead denied.");
    }

    But it still goes into the catch mode...

    Any idea on how to solve this problem?
    Help would be greatly appreciated.
    Thanks
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    can u send me ur js code where u make the request.
    then i think it ll be better to solve ur problem.

    kind regards.
    dmjpro.

    Comment

    • satishr23
      New Member
      • Mar 2007
      • 10

      #3
      Hi,
      Thanks for your reply..
      Here is my code..


      Code:
      url="http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml";
      function getRSS()
          { 
      	if (window.ActiveXObject)
      		{
      		ajaxobj = new ActiveXObject("Microsoft.XMLHTTP");
      		alert("microsoft xmlhttp");
      		}
      	else if (window.XMLHttpRequest)
      		{
      		ajaxobj = new XMLHttpRequest();
      		if (typeof netscape != 'undefined' && typeof netscape.security !=             'undefined') 
                      {
                       try {
                netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
                           }
                      catch (e) {
                                     alert('Error ' + e.message + ' occurred.');
                                   }
      		 }
               
      	       alert("xmlhttprequest");
      	     }
      	else
      		alert("not supported");
      		
      	try
      	{
      	ajaxobj.open("GET",url+"?sid="+Math.random(),true);
      	}
      	catch(error)
      	{
      	 alert("catch"+ error.description);   //script doesnt go beyond this in Firefox
      	 return false;
      	 }
             ajaxobj.onreadystatechange = function() {
      		if (ajaxobj.readyState == 4)
      		{
      			if (ajaxobj.status == 200)
      			{
      				if (ajaxobj.responseText != null)
      				{
      				processRSS(ajaxobj.responseXML);
      				}
      				else
      				{
      				 alert("Failed to receive RSS file from the server - file not found.");
      				return false;
      				}
      			}
      		 else
      			alert("Error code " + ajaxobj.status + " received: " + ajaxobj.statusText);
      		 }
      	}
      
      	ajaxobj.send(null);
          }

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        To get around the security (same domain), use JSON, e.g. link.

        Comment

        Working...