dongshie8450 2014-07-20 04:22
浏览 31

无法使用jquery php ajax添加注释

I want to add comment on pressing enter and want to store it to my database with the specific t_id for it so that i can show it on the page after submission but when i enter text and press enter it does nothing.and i am also suspicious about my add_comment.php fule query because t_id is forgien key in comments table and primary in topics i am at very beginer level in jquery,php and ajax...Any Help will be appreciated.

Here is my Jquery From Send.php

$(document).ready(function(){
        $('a').on('click',function(e){
            $('#Comments').html('<textarea id="D_Comment" name="D_Comment"></textarea>');
             $('a').on('input',function(ev){
              $('#Enter_Comments').on('click',function(event){

             var d_comnt = $('#D_Comment').val();


              if (event.which == 13) {
                alert("You Hit Enter");
                e.preventDefault();

              $.ajax({
                url     : "ajax/add_comment.php",
                type    : "POST",
                data    : {D_Comment : d_comnt},
                success : function(data){
                    console.log(data);
                },
                error   : function(data){
                    alert(data);
                }

              });
            }

            });

              // ev.preventDefault();
             // return false;
         });
              //e.preventDefault();
              return false;

  });
    });

and my html from send.php on same page with php showing post from database

<section id="Main_Content">

<?php
mysql_connect("localhost","root","") or die("Could not coonnect");
mysql_select_db("forum") or die("could not select db");
$last_id = mysql_real_escape_string($_GET['t_id']);
$sql   = "SELECT * FROM Topics WHERE t_id = '".$last_id."'";
$query = mysql_query($sql);

$row = mysql_fetch_assoc($query); 

    echo "<article>";       
    // echo $row['t_id'];   
    echo "<h2>".$row['name']."</h2>"."<br/>";
    //echo "<a href='#'>".$row['date']."</a>";
    // echo "<a href='#'>".$row['date']."</a>";
    echo "<p> Posted on ".$row['date']."</p>"."<br/>" ;
    echo "<p>".$row['detail']."</p>"."<br/>" ;
    echo "<a href='t_id=".$row['t_id']."' id='Enter_Comments'>"."Enter Comment". "</a>";
    echo "</article>";

?>
 <div id="Comments"></div> 
</section>

and my add_comment.php fiel is

<?php

mysql_connect("localhost","root","") or die("Could not coonnect");
mysql_select_db("forum") or die("could not select db");
$d_cmnt = mysql_real_escape_string($_POST['D_Comment']);
$t_id   = mysql_real_escape_string($_GET['t_id']);
$sql    = "INSERT INTO comments (comment,t_id,date) VALUES('$d_cmnt','$t_id',Now())";
$query  = mysql_query($sql);

if ($query) {
        echo "Success";
}
else{
    echo "Error";
}


?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)