« Outlook and Norton AntiVirus 2002 Making Firefox Faster »
Tracking UPS Packages via JavaScript
Posted January 3, 2005 – 1:51 pm by Yakov Shafranovich in Programming, ProjectsA recent post at TechDigits about tracking UPS packages via RSS and web services got me thinking if the same is possible via Javascript and the XmlHttpRequest object (in IE and Mozilla). Since Google’s Gmail and Google Suggest started using that object, it has become more popular. So after some thinking, I put together the following quick and dirty code snippet:
req = new XMLHttpRequest();
var strXML = ‘<?xml version=\’1.0\’?>’ +
‘<AccessRequest xml:lang=\’en-US\’>’ +
‘<AccessLicenseNumber>YOURLICENSEKEY</AccessLicenseNumber>’ +
‘<UserId>YOURUSERNAME</UserId>’ +
‘<Password>YOURPASSWORD</Password>’ +
‘</AccessRequest>’ +
” +
‘<?xml version=\’1.0\’?>’ +
‘<TrackRequest xml:lang=\’en-US\’>’ +
‘<Request>’ +
‘<TransactionReference>’ +
‘<CustomerContext>sample</CustomerContext>’ +
‘<XpciVersion>1.0001</XpciVersion>’ +
‘</TransactionReference>’ +
‘<RequestAction>Track</RequestAction>’ +
‘<RequestOption>activity</RequestOption>’ +
‘</Request>’ +
‘<TrackingNumber>1Z12345E1512345676</TrackingNumber>’ +
‘</TrackRequest>’;
req.open(’POST’, ‘https://www.ups.com/ups.app/xml/Track’, false);
req.send(strXML);
document.write(req.responseText);
This code on Mozilla browsers will retreive and post the raw XML information (you do need the security information for UPS’s website to make it work which is a bit of a security flaw). Once you got the information, then you can parse it via Mozilla’s or IE’s XSLT processors, or via regular DOM methods after parsing it into a DOM tree as follows:
var parser = new DOMParser();
var doc = parser.parseFromString(req.responseText, “text/xml”);
For Mozilla browsers, you also need to request a security permission from the user in order to access UPS’s website. A web proxy might be an answer to that problem but in any case here is the code:
netscape.security.PrivilegeManager.enablePrivilege(”UniversalBrowserRead”);
I don’t know how useful this can be since the security information is exposed, but it is a nice hack.
Tags: ajax, javascript, mozilla, rss, track2rss —
Permalink | Trackback URL | This post has















One Response to “Tracking UPS Packages via JavaScript”
… the same is possible via Javascript and the XmlHttpRequest object (in IE and Mozilla).
Just wanted to point out, the latest release of Opera 8 beta 1 also supports the XmlHttpRequest object.
By Daniel on Jan 3, 2005