Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Having trouble using XMLHttpRequest to refresh data



Another approach is to set the If-Modified-Since HTTP header to some time in the past.

req.setRequestHeader('If-Modified-Since', 'Wed, 15 Nov 1995 00:00:00 GMT');

Marc

On 21-May-05, at 11:26 AM, Thaddeus Cooper wrote:

This is a caching bug that I ran into as well. If the URL is the same every time then you get the undefined error. I "fixed" the problem by adding ?ts_cache=<currenttime> to the URL to make it different and the problem went away.

Hope that helps.

--Thaddeus O. Cooper

On May 21, 2005, at 8:45 AM, Blake Patterson wrote:


I have two chunks of HTML on my widget that I want to refresh with a timer, pulled from remote .js files that just do document.writes of HTML.  Poor man's RSS sort of - but my needs go beyond RSS so that's not an option for me.

Anyway, I wrote this demo that basically works:


I am trying to do the same thing in my widget, but it never works.  Let me explain.

In my loaded() function, called as onLoad in my BODY tag, I do this:


And that function I have defined as:

function loadXMLDoc(url) 
{
    if (window.XMLHttpRequest) {       
        req = new XMLHttpRequest();
        req.>
        req.open("GET", url, true);
        req.send(null);
    } 
}

...and this function calls:

function processReqChange() 
{
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
                    document.getElementById('news').innerHTML = "yo";
        } else {
            document.getElementById('news').innerHTML = "There was a problem retrieving the XML data:\n" + req.statusText;
        }
    }
}

And this is the block of code I am trying to replace (the element id = news)

    <span class="newsText">
        <br>
        <div id="news">start</div>
    </span>


...the problem is, req.readyState is always 0.  The state indicates UNDEFINED.  I do have:

    <key>AllowNetworkAccess</key>
    <true/>

In my plist.  What could be the issue?  I can hit the net fine from this machine.  I have been stumped for days here.  Any ideas?  The issue is not really whether it's updating the 'news' element id because, as I said, when I output req.readyState in the top of processReqChange, it's always 0...

req is defined as a global var at the start of the .js file for my widget.

Thanks for any help!




bp
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Dashboard-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Dashboard-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Dashboard-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/dashboard-dev/email@hidden

This email sent to email@hidden

References: 
 >Having trouble using XMLHttpRequest to refresh data (From: Blake Patterson <email@hidden>)
 >Re: Having trouble using XMLHttpRequest to refresh data (From: Thaddeus Cooper <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.