类方法中的全局变量

时间:2018-07-13 13:10:30

标签: php ajax class

我试图获取从ajax请求发送的变量的值,但是调试器中什么都没出现

Ajax:

$(document).ready(function(){
    var did=$('#did_hidden').val();
    $.ajax({
    type: 'POST',

    url: 'php/classes/Chat.class.php',
    data: { 
        'did': did

    },
    success: function(msg){

    }
});
    })

Chat.class.php

$didx=htmlspecialchars($_POST['did']);
public static function getChats($lastID){
        $lastID = (int)$lastID;

        global $didx;

        $result = DB::query('SELECT * FROM webchat_lines WHERE id > '.$lastID.' and deal_did="$didx" ORDER BY id ASC');

        $chats = array();
        while($chat = $result->fetch_object()){

            // Returning the GMT (UTC) time of the chat creation:

            $chat->time = array(
                'hours'     => gmdate('H',strtotime($chat->ts)),
                'minutes'   => gmdate('i',strtotime($chat->ts))
            );

            $chat->gravatar = Chat::gravatarFromHash($chat->gravatar);

            $chats[] = $chat;
        }

        return array('chats' => $chats);
    }

尽管我在课外进行了测试并且效果很好,但是无法在类方法内获取$didx值的原因是什么?

0 个答案:

没有答案