Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Tracking UPS Packages via JavaScript
* A 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
* I don't know how useful this can be since the security information is exposed, but it is a nice hack.
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>';'POST', '', false);
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment