0

I am working with an ecommerce platform and wanting to setup a script that can send the current order ID to a php script on my own external server.

When a customer checkouts, the final url is in the form of:

https://site.com/checkout?id=8d435a28&orderid=1002

I am able to insert js/ajax into that checkout page, but I am unsure how I can grab orderid=1002 and post it to my externally hosted php script.

How would I go about this? Thanks in advance!

  • Two small questions: Is your php script accessible via HTTPS too? Do you specifically need the "POST" method or would you accept "GET"? – dotpush Dec 08 '14 at 00:53
  • Yes it will be called via https. I suppose get would suffice as well. What did you have in mind –  Dec 08 '14 at 01:11

1 Answers1

0

See https://stackoverflow.com/a/901144/1106814 for function getParameterByName.

You can just do something like :

(function() {
    var orderId=getParameterByName('orderid'),
      beaconUrl = 'https://yourphpserver.example.org/beacon?orderid='+orderId,
      img = document.createElement('img');
    img.src= beaconUrl;
    img.style.width = '1px';
    img.style.height = '1px';
    document.body.appendChild(img);
})();

And then makes sure you receive information at https://yourphpserver.example.org/beacon.

Community
  • 1
  • 1
dotpush
  • 428
  • 3
  • 14
  • If you have time, how does this bypass browser cross domain restrictions? –  Dec 08 '14 at 02:01
  • 1
    It's basically the same as having an `` directly in your source code. There is no cross domain restriction for this (only possible restrictions preventing from loading non SSL images from an HTTPS web page). This kind of technique is used for a long time, analytics product often send the data to the third party server this way. – dotpush Dec 08 '14 at 02:09