SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot bobber205's Avatar
    Join Date
    Sep 2006
    Location
    Oregon
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XML Feeds and Javascript

    I'm having a heck of a time here. My ultimate goal is to make a widget that gets one line from an XML file and displays it. Once I get that down, I'll do other, cooler features.

    I've messed with javascript for years, so once I get past this first roadblock, I should be ok. I'm so glad you guys are here to help me!

    This Page I want

    Simple. First step, how do I connect to that page via XMLHttpRequest? I've done tons of things, nothing working. The code below is what I have right now, is case it's actually useful.

    Thanks. I will be very grateful for a response!

    Code:
    function getHTTPObject() { 
    
    var xmlhttp; 
    /*@cc_on @if (@_jscript_version >= 5) 
    try { 
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
    } 
    catch (e) { try 
    { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) { xmlhttp = false; } }
    @else xmlhttp = false; @end @*/  
    
    
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { 
    try { 
    xmlhttp = new XMLHttpRequest();
    }
    catch (e) { 
    xmlhttp = false; 
    } 
    }//end of try 
    return xmlhttp; } 
    
    //***************************
    
    function handleHttpResponse() {
    
    if (http.readyState == 4) {
    alert("ok to GO!");
    alert(http.responseXML);
    
    }
    
    }
    
     try {
        netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
       } catch (e) {
        alert("Permission UniversalBrowserRead denied.");
       }
    
    var http = getHTTPObject(); // We create the HTTP Object 
    http.overrideMimeType("text/rss");
    try {
    http.open("http:", "http://images.apple.com/downloads/dashboard/home/recent.rss" , true);
    }
    catch(e) {
    alert(e);
    }
    http.onreadystatechange = handleHttpResponse;
    
    
    http.send(null);
    Little messy, I know.

  2. #2
    Caveat surfer Buddy Bradley's Avatar
    Join Date
    May 2003
    Location
    Cambridge, UK
    Posts
    2,366
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This article has a very basic introduction to Ajax, with all the relevant functions.

  3. #3
    SitePoint Zealot bobber205's Avatar
    Join Date
    Sep 2006
    Location
    Oregon
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am getting
    "Permission denied to access XMLHttpRequest.open".


    I am only gettings this odd security-related issue in Firefox and not Safari. I tried using

    Code:
    try {
        netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
       } catch (e) {
        alert("Permission UniversalBrowserRead denied.");
       }
    But that does not work. Any ideas? (The image is the error I get when I try to use that code)
    Attached Images Attached Images

  4. #4
    I ♥ PHP
    Join Date
    Jul 2003
    Location
    Melbourne, Australia
    Posts
    579
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bobber, you cannot use Ajax to open a file in a different domain than the one you are calling from. You will need to create a second php/asp page to capture the data from the feed and then use Ajax on your new page to display it.

    Regards,
    Jordan

  5. #5
    SitePoint Zealot bobber205's Avatar
    Join Date
    Sep 2006
    Location
    Oregon
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But I am opening the page as a XMLHttpRequest. I am!

    I am getting data displayed. That's what's weird.

    And now on Firefox, I get an error message but I get my ok message anyway.

  6. #6
    SitePoint Zealot bobber205's Avatar
    Join Date
    Sep 2006
    Location
    Oregon
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by J Windebank
    bobber, you cannot use Ajax to open a file in a different domain than the one you are calling from. You will need to create a second php/asp page to capture the data from the feed and then use Ajax on your new page to display it.

    Regards,
    Jordan
    I am trying to make a widget and it won't have a PHP server to always run on.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •