Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 13th, 2012  |  syntax: JavaScript  |  size: 0.89 KB  |  hits: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. (function() {
  2.         if (window.addEventListener) {
  3.                 window.addEventListener('load', init, false);
  4.         } else {
  5.                 window.attachEvent("onload", init);
  6.         }
  7.        
  8.         function init() {
  9.                 var button = document.querySelector('.vPayNow');
  10.                 if (button.addEventListener) {
  11.                         button.addEventListener('click', getCheckoutUrl, false);
  12.                 } else  {
  13.                         button.attachEvent('onclick', getCheckoutUrl);
  14.                 }                      
  15.         }
  16.        
  17.         function getCheckoutUrl() {
  18.                 // XHR request to merchant backend service to return a checkout URL
  19.                 // This example expects the server to return a json string { url: 'http://examplecheckouturl.com' }
  20.                 var xhr = new XMLHttpRequest();
  21.                 xhr.onreadystatechange = function(){
  22.                         if (xhr.readyState === 4 && xhr.status === 200) {
  23.                                 jcz.open(JSON.parse(xhr.responseText).url);
  24.                         }
  25.                 };
  26.                 xhr.open('GET', 'service', true);
  27.                 xhr.setRequestHeader('Accept', 'application/json');
  28.                 xhr.send();            
  29.         }
  30. }());