jquery会干扰php吗? [英] Does jquery interfere with php?

查看:59
本文介绍了jquery会干扰php吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试限制评论和回复评论,并在达到限制后显示错误消息。我已成功限制评论和评论回复,并在仅提示评论时成功提供了错误消息,而不是评论回复。

I am trying to limit comments and replies to comments and display an error message once the limit is reached. I have successfully limited comments and comment replies, and successfully provided the error message when prompted ONLY for the comments, and not the comment replies.

评论回复有一点点jquery与他们一起工作,这是我唯一能看到的导致消息不显示的东西。我尝试了其他方法,然后使用当前正在使用的方法。

The comment replies have a little bit of jquery working with them, so that's the only thing I can see that would be causing the message not to display. I have tried other methods then the one currently being used.

$valid = true;
$max_post_per_day = 5;
$max_reply_per_day = 5;

//THE REGULAR COMMENTS STRUCTURE THAT IS SHOWING THE ERROR MESSAGE PROPERLY

$query = "SELECT COUNT(*) FROM `cysticBlogComments`
              WHERE `userID` = $auth->id
                AND `date` = CURDATE()";
    $result = mysql_query($query, $connection);
    $post_count = mysql_result($result, 0);
    $error_msgs_max_comment[] = "Whoops! You have reached the maximum amount of comments allowed for the day.";

    if($post_count >= $max_post_per_day)
    {
        $valid = false;
    }
    else
    {

    $query = "INSERT INTO `cysticBlogComments` 
                                    ( `blogID`,
                                      `userID`,
                                      `commentBody`,
                                      `status`,
                                      `date`,
                                      `time`
                                      ) VALUES (

                                      '" . $blogID ."',
                                      '" . $auth->id ."',
                                      '" . mysql_real_escape_string($_POST['BlogComment']) ."',
                                      'active',
                                      '" . date("Y-m-d") . "',
                                      '" . date("G:i:s") . "')";


    mysql_query($query, $connection);

}

<?php if(isset($_POST['commentBlogSubmit']) && $post_count >= $max_post_per_day ) {
                foreach($error_msgs_max_comment as $msg) { ?>
                <div id="error_x">
                <?php echo $msg; ?>
                </div>
                <?php }
                }?>

//THE REPLY COMMENT STRUCTURE THAT IS LIMITING BUY NOT DISPLAYING ERROR AND HAS JQUERY WITH IT

$query = "SELECT COUNT(*) FROM `CysticBlogComments_replies`
                      WHERE `FromUserID` = $auth->id
                        AND `date` = CURDATE()";
            $result = mysql_query($query, $connection);
            $post_count = mysql_result($result, 0);
            $error_msgs_max_reply[] = "Whoops! You have reached the maximum amount of replies allowed for the day.";

            if($post_count >= $max_reply_per_day)
            {
                $valid = false;
                echo $error_msgs_max_reply;
            }
            else
            {

    $query = "INSERT INTO `CysticBlogComments_replies`
                                        ( `BlogCommentID`,
                                          `FromUserID`,
                                          `comment`,
                                          `status`,
                                          `date`,
                                          `time`
                                        ) VALUES (

                                        '" . mysql_real_escape_string($_POST['comment']) ."',
                                        '" . $auth->id ."',
                                        '" . mysql_real_escape_string($_POST['reply'])."',
                                        'active',
                                        '" . date("Y-m-d") . "',
                                        '" . date("G:i:s") . "')";

    mysql_query($query, $connection);
}

<?php if(isset($_POST['sub_comment_reply']) && $post_count >= $max_reply_per_day ) {
                foreach($error_msgs_max_reply as $msg) { ?>
                <div id="error_x">
                <?php echo $msg; ?>
                </div>
                <?php }
                }?>

//THE JS FOR THE REPLIES

<script type="text/javascript">
        $(document).ready( function() {

            $.localScroll({ offset:{top:-40,left:0} });

            $("a.reply_link").click( function() {
                $("#"+$(this).attr('name')).fadeIn('slow');
            });

            $(".respond_nevermind a").click( function(event) {
                event.preventDefault();
                var reply_box = document.getElementById($(this).attr('href'));
                $(reply_box).css('display','none');

                var reply_textarea = document.getElementById($(this).attr('href')+"_textarea");
                $(reply_textarea).val('');
            });
        });
</script>


推荐答案

PHP在执行JavaScript之前在服务器上运行,所以两者无法互动。 JavaScript 可能存在PHP生成的HTML问题(换句话说,只有JavaScript错误)或HTML本身可能包含错误,例如缺少关闭> 或引用。

PHP operates on the server before JavaScript is ever executed so the two can't be interacting. The JavaScript could be having issues with the HTML produced by the PHP, though (in other words, there's just a JavaScript error) or the HTML itself may contain an error such as a missing closing > or quote.

这篇关于jquery会干扰php吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆