doutang8098 2014-12-07 22:42
浏览 11
已采纳

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!

  • 写回答

1条回答 默认 最新

  • donpvtzuux37724 2014-12-08 01:46
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序