几天来我一直在试图找出问题所在。在发送和检索我的数据时,它没有发布到我的div中。为什么?我进行了测试,发现我出现了SyntaxERROR意外字符。并且可以找到它。

有人可以浏览一下,并告诉我任何错误。

<script>
$(document).ready(function(){
    $("form#mycommentform").submit(function() {

        var streamidcontent = $(this).children("#streamidcontent").val();
        var contents = $(this).children("#contents").val();
        $.ajax({
            type: "POST",
            url: "comment_add.php",
            cache: false,
            dataType: "json",
            data: { streamidcontent: streamidcontent, contents: contents },
            success: function(data){
                $("#containerid").html('<div class="stream_comment_holder" id="comment_holder_'+data['comment_streamitem']+'">\
                <div id="comment_list_'+data['comment_streamitem']+'">\
                <div id="tgy"></div><div class="stream_comment" id="comment_'+data['comment_id']+'" style="margin-top:0px;">\
                <table width=100%><tr><td valign=top width=30px></a><td valign=top align=left>\
                <a href="/profile.php?username='+data['username']+'">'+data['first']+'</a>\
                <div class="commentholder">'+data['first']+'</div><br/>\
                <div id="commentactivitycontainer"></div></div></table></div></div>\
                <div class="form"><form id="mycommentform" method="POST" class="form_statusinput">\
                <input type="hidden"  name="streamidcontent" id="streamidcontent" value="'+data['comment_streamitem']+'">\
                <input type="text" name="contents" id="contents" placeholder="Say something" autocomplete="off">\
                <input type="submit" id="button" value="Feed"></form></div>\
                <div class="stream_comment_holder" style="display:;"><div class="like_name"><b>\
                <a href="profile.php?username='+data['username']+'">You Like This</a>\
                </b></div></div>');
                  alert("SUCCESS!!!");
 },
 error: function (xhr, ajaxOptions, thrownError) {
    alert(xhr.statusText);
    alert(xhr.status);
    alert(thrownError);
 }
 });
        return false
    });
 });
 </script>


回应

INSERT INTO streamdata_comments(comment_poster, comment_streamitem, comment_datetime, comment_content) VALUES (10,4090,UTC_TIMESTAMP(),'fff'){"comment_id":"2016","comment_streamitem":"4090","username":"hazy","id":"10","first":"Lucy","middle":"","last":"Botham"}


PHP页面

<?php
session_start();
require"include/rawfeeds_load.php";

if(isset($_POST['streamidcontent'])&isset($_POST['contents'])){
rawfeeds_user_core::add_comment($_POST['streamidcontent'],$_POST['contents']);


$json = array();
$check = "SELECT comment_id, comment_datetime, comment_streamitem, comment_poster FROM streamdata_comments WHERE comment_poster='".$_SESSION['id']."' AND comment_streamitem='".$_POST['streamidcontent']."' ORDER BY comment_datetime DESC";
$check1 = mysqli_query($mysqli,$check);
$resultArr = mysqli_fetch_array($check1);
$json['comment_id'] = $resultArr['comment_id'];
$json['comment_streamitem'] = $resultArr['comment_streamitem'];
mysqli_free_result($check1);

$check = "SELECT * FROM users WHERE id=".$_SESSION['id']."";
$check1 = mysqli_query($mysqli,$check);
$resultArr = mysqli_fetch_array($check1);
$json['username'] = $resultArr['username'];
$json['id'] = $resultArr['id'];
$json['first'] = $resultArr['first'];
$json['middle'] = $resultArr['middle'];
$json['last'] = $resultArr['last'];
mysqli_free_result($check1);

echo json_encode($json);
}
?>

最佳答案

正如上面的@thomas。我正在将SQL查询回显到我的函数中。我删除了它,现在可以正常工作了。

10-08 11:11