Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php AJAX不起作用,成功函数起作用了吗?_Php_Html_Ajax - Fatal编程技术网

Php AJAX不起作用,成功函数起作用了吗?

Php AJAX不起作用,成功函数起作用了吗?,php,html,ajax,Php,Html,Ajax,success函数正在工作,但数据没有进入数据库 $(document).ready(function() { $("#ChatText").keyup(function(e){ if(e.keyCode == 13) { var ChatText = $("#ChatText").val(); $.ajax({ type:'POST', url:'Insert

success函数正在工作,但数据没有进入数据库

$(document).ready(function() {
    $("#ChatText").keyup(function(e){
        if(e.keyCode == 13) {
            var ChatText = $("#ChatText").val();
            $.ajax({
                type:'POST',
                url:'InsertMessage.php',
                data:{ChatText:ChatText},
                success:function(){
                    $("#ChatText").val("");
                }
            });
        }
    });
    setInterval(function(){
        $("#ChatMessages").load("DisplayMessages.php");
    },15000000);

    $("#ChatMessages").load("DisplayMessages.php");
});
PHP


调试时可以做的一件事是回显您的sql查询,并查看您是否得到了正确的查询。您可以在phpMyAdmin中尝试该事件查询,并查看发生了什么。如果没有调试,很难说出任何事情。

请共享您的php代码,我们对此无能为力。我使用了此php代码并使用了提交按钮,效果很好。请更新您的问题,而不是将其发布在评论中。您确定是$db而不是$db。。。这实际上可以避免在
$ct
变量周围没有引号的问题<代码>值(“$uid”、“$gid”、$ct)
。我几乎可以肯定,通过正确的错误调试,您会在这里发现一个SQL错误。当然,假设您的chatterxt
具有名称
chatterxt
<?php
session_start();
include "connectToDB.php";

if(isset($_POST['ChatText'])){
    $uid = $_SESSION['userid'];
    $gid = $_SESSION['GameId'];
    $ct = $_POST['ChatText'];
    $sql = "INSERT INTO `chats`( `ChatUserId`, `chatGameId`, `ChatText`) VALUES ('$uid','$gid',$ct);";
    $result = mysqli_query($_db , $sql);
}
?>