weixin_33749242 2019-04-09 15:34 采纳率: 0%
浏览 32

$ _SESSION名称未定义[重复]

This question already has answers here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/23740548/how-do-i-pass-variables-and-data-from-php-to-javascript" dir="ltr">How do I pass variables and data from PHP to JavaScript?</a>
                            <span class="question-originals-answer-count">
                                (20 answers)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2020-01-06 21:49:57Z" class="relativetime">4 months ago</span>.</div>
        </div>
    </aside>

This is translated, I'm sorry if there's something wrong.

I have a problem and it is that when I insert the name of the session it tells me that it is undefined. I did tests inserting the manual username and if everything works.

https://imgur.com/bFObycd

<? php
session_start ();
echo var_dump ($ _SESSION);
?> 

The first thing that the php has is this, as you can see the var_dump correctly shows the user's name.

The message of (username) is not defined in the console.

I'm doing it with a modal.

The textbox is inserted correctly, I just need the name of the session that inserts it. The database works correctly (I tried inserting the parameters manually)

As you can see with var_dump correctly shows the user name of the session. Also insert the content of textarea well, just need to insert the name of the session

        <script>
        $(inicializarEventos);
        function inicializarEventos(){
            $("#insertar").click(insertarSugerencia);
        }
        function insertarSugerencia(){
          var nombreUsuario= <?php echo  $_SESSION['usuario']?>;
          var textoSugerencia=$("#textoSugerencia").val();
          console.log(nombreUsuario,textoSugerencia);
          $.ajax({
            url:"bd/bd.php",
            method: "POST",
                                                                                            data:{nombreUsuario:nombreUsuario,textoSugerencia:textoSugerencia},
        dataType:"JSON",
        success:function(){
          alert ("Sugerencia enviada correctamente");
          $("#modal1").modal("hide");
          }
           });
           }

        </script>
</div>
  • 写回答

1条回答 默认 最新

  • weixin_33691700 2019-04-09 15:41
    关注

    You have to put the contents of your variable between quote as it is a string:

    var nombreUsuario= "<?php echo  $_SESSION['usuario']?>";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器