doufu7835 2014-07-03 15:11
浏览 38
已采纳

如何从javascript发送的PHP中接收数据[重复]

This question already has an answer here:

I am sending some data from my pain page to app.php using javascript

$(document).on('click', '.app' , function(){
        var data=$(this).attr("id");
        window.location="application/app.php?data="+data;   //data send in this statement
    });

my php code is this :

<?php
if($_GET['data'])
{
    echo $app_id=$_GET["data"]; receiving data 

}
?>

It works sometime but now it is giving Notice in an alert box: Undefined index data in app.php. But it is showing the echo.


I want to know how I can receive the data I need using $_POST or $_GET. like we receive by making an Ajax call. But I haven't specified something like this in Javascript. is there any way to this?

I want to clarify that the data exists and it is non empty because echo is successfully printing that on the page

</div>
  • 写回答

2条回答 默认 最新

  • douyan1927 2014-07-03 15:16
    关注

    Try this:

    <?php
    if(!empty($_GET['data']))
    {
        $app_id = $_GET['data']; // receiving data 
    }
    ?>
    

    Please be aware that passing data without validation is not secure. Reccomended reading: https://www.owasp.org/index.php/Category:OWASP_Top_Ten_Project

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?