2013-08-16 97 views
1

即时工作的评论系统,但我不知道如何解决这个bug .. 当我写东西到文本区域并按提交,然后没有任何反应。 该文件的链接是正确的! 当我不输入任何东西到textarea,然后它显示给定的错误。评论系统jQuery/ajax php mysql

这里是comment.php文件

<script type="text/javascript"> 
    function toggle_comment(id) { 
     var e = document.getElementById(id); 
     if(e.style.display == 'block') 
      e.style.display = 'none'; 
     else 
      e.style.display = 'block'; 
    } 

    $(function() { 

$(".submit").click(function() { 

    var comment = $("#comment").val(); 
    var dataString = 'comment=' + comment; 

    if(comment=='') 
    { 
    alert('Please Give Valide Details'); 
    } 
    else 
    { 
    $("#flash").show(); 
    $("#flash").fadeIn(400).html('<img src="ajax-loader.gif" align="absmiddle">&nbsp;<span class="loading">Loading Comment...</span>'); 
$.ajax({ 
     type: "POST", 
    url: "index.php?s=comment", 
    data: dataString, 
    cache: false, 
    success: function(html){ 

    $("#flash").hide(); 

    } 
}); 
} 
return false; 
    }); 



}); 
</SCRIPT> 


<a class="sitelinksblue" onclick="toggle_comment('commentfield');" style="font-family: Verdana, Geneva, sans-serif;font-size:12px;font-weight:bolder;">+ Kommentar abgeben für Englisch Für Anfänger</a> 
<?php 
if($_POST) { 
$sqlCmd = "INSERT INTO topmovies.comments 
     (username,comment,date) 
     VALUES 
     ('".mysql_real_escape_string($_SESSION['user_username'])."','".mysql_real_escape_string($_POST["comment"])."','".$sqlZeit."')"; 
$sqlQry = mysql_query($sqlCmd,$sqlHp); 
if (!$sqlQry) { 
    die('Invalid query: ' . mysql_error()); 
}else { echo'Comment Added!';} 
} 
?> 

<div id="commentfield" style="display:none"> 
    <form method="POST" action="#"> 
     <p>Dein Name: <?PHP echo $_SESSION['user_username']; ?></p> 
     <textarea class="interfaceforms" name="comment" id="comment" rows="5" cols="20" maxlength="1555" value=""></textarea><br /> 
     <input type="submit" class="submit" value="Submit" /> 
    </form> 
</div> 
<?php 
$sql=mysql_query("select * from topmovies.comments ORDER BY date DESC"); 
while($row=mysql_fetch_array($sql)) 
{ 
$username=$row['username']; 
$comment=$row['comment']; 
$date=$row['date']; 
$name=$row['name']; 
?> 

<div id="comments" name="comments"> 
<div class="comments" style="padding-top:5px;"> 
     <BR> 
    <table width="746px" style="display:inline;" border="0" cellspacing="0" cellpadding="0"> 
     <tr> 
     <td rowspan="4" valign="top" width="154px" style="padding-right:19px;"><img style="display: block; padding-top:10px;" src="http://img.movie4k.to/img/user_top.gif" height="8px"/> 
     <span class="test"><?php echo $username; ?><br /> 
     <br /> 
     <font size=1><?PHP echo date("d-m-Y", strtotime($date))?></br> 
     <?PHP echo date("H:i", strtotime($date))?></font></span> 
     <img style="display: block; background-color: #AFAFAF; padding-left:10px; padding-right:10px;" src="http://img.movie4k.to/userpics/476090.gif" width=40 height=50/> 
     <img style="display: block;" src="http://img.movie4k.to/img/user_bottom.gif" height="8px"/></td> 
     <td colspan="2" valign="bottom" height="8px"><img style="display: block; padding-top:10px;" src="http://img.movie4k.to/img/comment_top2.gif" height="8px"/></td> 
     </tr> 
     <tr> 
     <td rowspan="2" width="522px" class="comment" valign="top" bgcolor="#E3E3E3" style="padding-left:10px; padding-right:17px;"> 
     <?php echo $comment; ?> 
     </td> 
     <td width="85px" valign="top" bgcolor="#E3E3E3" style="font-size:19px;"> 
     </td> 
     </tr> 
     <tr> 
     <td bgcolor="#E3E3E3" valign="bottom"></td> 
     </tr> 
     <tr> 
     <td colspan="2" valign="top" height="8px"><img style="display: block;" src="http://img.movie4k.to/img/comment_bottom2.gif" height="8px"/></td> 
     </tr> 
    </table> 
</div> 
</div> 
<BR /> 
<?php 
} 
?> 

希望有人知道什么是错! 也许可以给我一些的窍门出于安全/性能更好等

+2

有点调试会走很长的路,是通过ajax发布到脚本的形式? – 2013-08-16 03:52:46

+0

你确定没有任何反应?你有没有检查你的控制台日志?你没有做任何成功的事情 - '成功:函数(html){... //这里除了$(“#flash”)之外什么也没有。 }' – Sean

回答

1

可以通过各种原因而产生错误你,但至少你的代码应该有一个divid命名flash

<div id='flash'>...</div>` 

HTML部件上没有这样的div

0

尝试将错误事件添加到您的ajax调用中,以便如果您的ajax请求中存在错误,那么它将显示错误。做类似的事情:

$.ajax({ 
    type: "POST", 
    url: "index.php?s=comment", 
    data: dataString, 
    cache: false, 
    success: function(html){ 
     $("#flash").hide(); // no DOM found with id flash this is also the error 
    }, 
    error: function(e){ 
     alert("something wrong with ajax "+ e); // OR 
     console.log(e) 
    } 
});