Ajax发布请求无法正常运行

时间:2017-08-30 15:06:29

标签: php ajax

我不明白为什么我的ajax在发布后没有返回任何值。我在html表中显示注册用户的数量,并允许管理员点击每个计数以查看用户名列表。

我的html显示注册用户的数量:

$sql2 = "SELECT COUNT(*) AS count FROM reg WHERE reg_id = '".$row['reg_id']."'";
$result2 = $conn->query($sql2);

if ($result2->num_rows > 0) {
    while($row2 = $result2->fetch_assoc()) {
        echo '<a class="slot" data-slotid='.$row['reg_id'].' href="">'.$row2['count'].'</a>';
    }
}

$sql2 = NULL;

Ajax请求:

$('.slot').on('click', function(){
    var slotid = $(this).data('slotid');
    $.ajax ({
        type: 'POST',
        url: 'my-domain.com/ajax-request',
        data: { slotid : slotid },
        success : function(htmlresponse) {
            $('#user_list').html(htmlresponse);
            console.log(htmlresponse);
        }
    });
});

我的php函数从另一个文件过滤数据库行:

if(isset($_POST['slotid'])){
    // Mysql SELECT statement and echo query result
}

如果我在alert(slotid)后面的var slotid = $(this).data('slotid');放置在ajax函数中,它将为每个点击的链接显示正确的值。但是当我在php端尝试echo $_POST['slotid'];时,没有返回值。看起来整个页面都很新鲜。

0 个答案:

没有答案
相关问题