The Harmony RightAddress JavaScript client is a JavaScript library that can be included on a web page, allowing website users to connect directly to the Harmony RightAddress services without any server-side processing requirements. For versions earlier than 1.8.0 please refer to the previous version of Harmony RightAddress JavaScript Client for code snippet.
For the best experience, we recommend you to use the latest versions of your favourite browsers.
Copy and paste the following code snippet into your web page.
Before you can use the Harmony RightAddress client, you must make sure you have:
The versions of the JavaScript client can be downloaded using the following link:
Before making service requests, the client must be initialised. This is done by invoking the
init
method on the global Harmony
object:
Harmony.init({String} username, {String} password, {String} locale);
This method must be called before any other methods are invoked on the Harmony
object.
<script type="text/javascript"> Harmony.init("webUser", "password", Harmony.AUSTRALIA); </script>
During initialisation, the client environment is set to Production and the protocol is set to CORS. To use the
Production environment or the JSONP protocol, the useEnv
and useProtocol
methods can be
used.
<script type="text/javascript"> // Use the Production environment Harmony.useEnv(Harmony.ENV_PRODUCTION); // Use the JSONP protocol Harmony.useProtocol(Harmony.JSONP); </script>
Once the Harmony RightAddress client has been initialised, any methods available to the supplied user can be invoked.
These methods are invoked using the global Harmony
object.
The following example invokes the find
method with the single-line address '1 abc street' in Canada.
The callback method then output the addresses in a textarea with the id 'output':
<script type="text/javascript"> Harmony.init("webUser", "password", Harmony.AUSTRALIA); Harmony.v2.find({ fullAddress:"1 abc street" , country: "ca"}, null, function(response) { var outputText = ""; // Check if the request was successful. if (response == Harmony.SUCCESS) { // Fill the output text with the single-line address results. for (var i = 0; i < response.payload.length; i++) { outputText += response.payload[i].fullAddress + "\n"; } } else { // Fill the output text with the error message(s). for (var i = 0; i < response.messages.length; i++) { outputText += response.messages[i] + "\n"; } } // Put the output text in the textarea (with id 'output') document.getElementById("output").value = outputText; } ); </script>
See the Harmony RightAddress JavaScript client API documentation for details on invoking the other Harmony RightAddress service methods.