JavaScript / Ajax - 将当前页面URL发送到外部PHP SCript

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!

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.