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: Using XML in Widgets/Javascript




You're almost there - the difference between loading an XML file through the XMLHttpRequest object versus sending out a request via HTTP is that you don't get a HTTP status code when getting the file locally. Here's an example which parses an XML file called "config.xml" in the top level of the widget bundle:


function doRequest(request) {
  request.onreadystatechange = onProcessReadyStateChange;
  request.overrideMimeType("text/xml");
  request.open("GET", "config.xml", true);
  request.setRequestHeader("Cache-Control", "no-cache");
  request.send(null);
}

function onProcessReadyStateChange() {
    // only if request shows "loaded"
    if(request.readyState == 4) {
        if(request.status == 200 || request.responseXML) {
          clearTopicList();
          buildTopicList(request.responseXML);
        } else {
            alert("There was a problem retrieving the XML data:\n";; +
                request.status + " : " + request.statusText);
         }
    }
}



_______________________________________________
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


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.