dongtang6718 2016-03-06 17:36
浏览 24

使用javascript通过URL将参数传递给PHP文件

The data we want to send: parameter code with value A123, parameter price with value 12.45, and parameter date with value 12-3-2016. Assume that the server-side data processing file is called computePrice.php, and the domain of the server is www.mydomain.com.

My guess is www.mydomain.com?code=A123&price=12.45&date=12-3-2016

  • 写回答

2条回答 默认 最新

  • dongpao1918 2016-03-06 17:56
    关注

    You can take those URL values using $_GET. Do this like so:

    <?php
    $code = $_GET['code'];
    $price = $_GET['price'];
    $date = $_GET['date'];
    ?>
    

    Make sure when you redirect to that page you run a urlencode() on each variable. For example:

    <?php
    $code = "A123";
    $price = "12.45";
    $date = "12-3-2016";
    $url = "www.mydomain.com?code=".urlencode($code)."&price=".urlencode($price)."&date=".urlencode($date);
    header('Location: '.$url);
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度