doubo1883 2012-08-16 03:43
浏览 49
已采纳

函数在通过jquery进行警报时创建大空间

I have a function which deals with sessions and cookies.

functions.php

function getUser()
{
     if(isset($_COOKIE["auth"]))
     {
         /* check cookie */
         echo $_COOKIE['auth'];
     }else if(isset($_SESSION["auth"])){
         echo $_SESSION["user_auth"];
     }
}

I also have a form and there's an alert associated with it. I have an ajax that when user submits the form, alert the function.

Everything works, but the only issue is that the alert pops up with lots of spaces in it. I've tried to use

trim(getUser);

and str_replace("","",getUser());

And this is causing me problems because I'm trying to input the session value or cookie value into mysql database. When I check if there's any values inside my mysql database, its just empty, and its not NULL.

Thanks!

AJAX:

form.php

$(".inputSubmit").submit(function(e){
      e.preventDefault();
      var inputs= $('.inputForm').serialize();
      $.ajax({
           url: "submit.php",
           type: "POST",
           data: input,
           error: function(data){
                 alert(data.responseText);  
                 alert(data.responseStatus);
                 alert(data);
           }
      }).done(function(data){
           alert(data);
      });
});

submit.php

require "functions.php";

$users = str_replace("","",getUser());
echo $users;

lets say i have the alert box:

--------------------------------------
|                                    |
|                                    |
|                                    |
|                                    |
|                                    |
|  1                                 |
|                                    |
|                                    |
|                           OK       |
--------------------------------------

the 1 is the session output. the okay is the ok button when alert is popped out. Usually the 1 should be higher and smaller alert box, but its expanded as if there's white space.

  • 写回答

3条回答 默认 最新

  • doushifang4382 2012-08-16 03:56
    关注

    You need to return, not echo.

    function getUser()
    {
         if(isset($_COOKIE["auth"]))
         {
             /* check cookie */
             return $_COOKIE['auth'];
         }else if(isset($_SESSION["auth"])){
             return $_SESSION["user_auth"];
         }
         return "";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题