dongzhouhao4316 2015-05-12 14:38
浏览 96
已采纳

无法从GET获取变量,但可以从var_dump($ _ GET);

Trying to use a simple AJAX call, where I can pass a variable around and display in the modal. That side works, however I cant retrieve the variable from the GET.

The following echo var_dump($_GET); ->

array(2) { ["VALUE I WANT"]=> string(0) "" ["_"]=> string(13) "1431441301242" }

However, $TempName = $_GET['Name']; returns no value?

AJAX:

$('#exampleModal').on('show.bs.modal', function (event) {
   var button = $(event.relatedTarget) // Button that triggered the modal
   var recipient = button.data('whatever') // Extract info from data-* attributes
   var modal = $(this);
   var dataString = recipient;


    $.ajax({ 
        type: "GET", 
        url: "/getEventDetails.php/", 
        data: dataString, 
        cache: false, 
        success: function (data) { 
            console.log(data); 
            console.log(dataString); 
            console.log(recipient); 
            $('.dash').html(data); 
        }, 
        error: function(err) { 
            console.log(err); 
        } 
    });  
})
  • 写回答

2条回答 默认 最新

  • dongzong3053 2015-05-12 14:43
    关注

    You haven't assigned a name to your value in JS. PHP REQUIRES form submissions be in key=value format so it can built the _GET/_POST arrays. Since you haven't provided a name, there's no key for PHP to build the array with - no key, no value.

    Try

    data: {"foo":dataString}
    

    then $_POST['foo'].

    Alternatively, if you're sending over only a single value, then you can do

    $value = file_get_contents('php://input');
    

    to read the raw post data.

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

报告相同问题?

悬赏问题

  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题