执行Ajax代码时出错

时间:2016-03-08 10:58:15

标签: php jquery ajax

这是包含表单的div。

<div style="margin-left:50px;">
<div align="left" style="margin-bottom:10px;">
    <?php 
    //Getting all the comments corresponding to a particular 
    //herb and disease
    $ch = $dhb;
    $cd = $dnm;
    $cu = $uid;
    $getComment->execute();
    $getComment->bindColumn("c_id", $cid);
    $getComment->bindColumn("c_content", $content);
    $getComment->bindColumn("c_writer", $writer);

    while ($getComment->fetch()) {
        //Getting only the comments written by a particular user
        $getCommentUser->execute();
        $getCommentUser->bindColumn('user_fname', $cfName);
        $getCommentUser->bindColumn('user_lname', $clName);
        $getCommentUser->fetch();
    ?>
    <div style="background-color:#f6f7f8;">
        <font style="font-size:14px; color:#4c5d98"><b><?php echo "@" . $cfName . " " . $clName ?></b></font>
    </div>
    <div style="background-color:#f6f7f8;">
        <font style="font-size:14px;"><?php echo $content ?></font>
    </div>
    <div style="margin-bottom:10px; background-color:#FFF;">
    </div>
    <?php 
    } 
    ?>
    <div id="rslt">
    </div>
</div>
<?php 
    if (isset($_SESSION['uid'])) { 
        $i++;
?>
<div align="center" style="background-color:#f6f7f8;">
    <table width="98%">
        <form method="post">
            <tr>
                <td>
                    <textarea rows="1" id="<?php echo $i ?>" class="form-control" name="content" style="width:100%; resize:none;" placeholder="Add comment"></textarea>
                </td>
            </tr>
            <tr>
                <td align="center">
                    <input type="hidden" id="uid" name="uid" value="<?php echo $uid ?>">
                    <input type="hidden" id="herb" name="herb" value="<?php echo $dherb ?>">
                    <input type="hidden" id="disease" name="disease" value="<?php echo $diseases ?>">
                    <input type="submit" onClick="postComment('<?php echo $i ?>')" class="btn btn-sm btn-primary pull-left margin-top" name="add" value="Comment">
                </td>
            </tr>
        </form>
    </table>
</div>
<?php } ?>
<div>
    <p id="rslt">
    </p>
</div>

这是javascript代码

 <script type="text/javascript">
function postComment(id) {
    var cuser = $("#uid").val();
    var ccontent = $("#" + id).val();
    var cdisease = $("#disease").val();
    var cherb = $("#herb").val();
    var dataString = 'cuser='+ cuser + '&ccontent=' + ccontent + '&cdisease=' + cdisease + '&cherb=' + cherb;

    if (ccontent == '') {
        alert('Please Give Valid Details');
    } else {
        alert(dataString);

        $.ajax({
            url:  "child.php",
            data: dataString,
            type: "POST",
            success: function(resp) { 
                document.getElementById('rslt').innerHTML = resp;
            },
            error: function(e) {  
                alert('Error: '+ e);  
            }  
        });
    }
}
</script>

javascript运行完美。在执行ajax代码期间,控制转移到comment.php页面,并且comment.php中的查询完美执行但返回代码返回错误而不是成功。任何人都可以帮忙。[child.php]

http://i.stack.imgur.com/ers07.png

0 个答案:

没有答案