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.

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

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程