与jQuery和JS Pagination冲突,Pagination没有合作

时间:2011-08-28 18:23:46

标签: php javascript jquery database conflict

JPagination无法将<div><li>分页。我不知道它是否与ID有冲突,或者它是PHP,或者究竟是什么,我希望有人可以帮我弄清楚发生了什么。

所以这就是我得到的。首先,这是我的HTML。这是我正在做的一个页面,它会将“发布您的文字”发布到墙上(这是一个<div>并带有<ul>)。这是HTML正文:

    <div id="head">
    <form name="postbar_add_post" id="postbar_add_post" method="post">
        <fieldset>
            <legend>What are you doing now? ...</legend>
            <input type="text" name="addcontentbox" id="addcontentbox" maxlength="200" />
            <input type="submit" name="addpost" value="Submit" class="submit" />
            </fieldset>
    </form>
    </div>

    <div id="cuerpo"><ul id="wall"></ul></div> 

好的,所以,在文档的头部,我得到了jQuery调用,还有一个名为JPagination的插件,而且在头上我得到了一个脚本,这将使内容“发布到墙上”只是为了确保我做得对,这就是我在文件头上的内容:

    <script src="http://c.fzilla.com/1286136086-jquery.js"></script> 
    <script src="http://c.fzilla.com/1291523190-jpaginate.js"></script>  

    // This is the script to post whats typed on the input to the div called wall:

    <script type="text/javascript">
    $.noConflict();
    jQuery(document).ready(function(){
        jQuery("form#postbar_add_post").submit(function() {
            var addcontentbox = jQuery('#addcontentbox').attr('value');

            if ( addcontentbox.replace(/\s/g,"") == "" ) return false;

    jQuery.ajax({
    type: "POST",
    url: "postear.php",
    data:"addcontentbox="+ addcontentbox,
    success: function(){
    jQuery("ul#wall").prepend("<li>"+addcontentbox+"</li>");
    jQuery("ul#wall li:first").fadeIn();
    document.postbar_add_post.addcontentbox.value='';
    document.postbar_add_post.addcontentbox.focus();
    }
    });
    return false; 
    });
    });
    </script>


    // and this would be where I try to paginate the content

    <script type="text/javascript">
        $(document).ready(function() {
            $("#wall").jPaginate();        
        });
    </script>

所以,这个帖子很棒!但是分页永远不会发生,如果我改变函数将其应用于父<div>,没有任何反应,它保持不变。在从jQuery添加“noconflict”之前,它甚至都不起作用。

为了防止需要,我在这里留下了第一个函数调用的PHP:

    <?php
    if( isset($_POST['addcontentbox']))
       {
       // Connection to Database
       include('config.php');

       // NO Query Injection
       $message = mysql_real_escape_string($_POST['addcontentbox']);

       // echo
       $sql = 'INSERT INTO WALL (message) VALUES( "'.$message.'")';
       mysql_query($sql);

       echo $message;
       }
    else
       { 
       echo '0';
       }
    ?> 

任何形式的指导或解决方案都将不胜感激。

1 个答案:

答案 0 :(得分:0)

我刚刚快速阅读了你的问题,我认为你使用了很多插件,所以我认为在使用多个插件时会遇到问题,所以总是用自调整函数包装你的javascript代码,比如

(function($){

  /// Your page code here
  // Here you can use $ 
  // We are passing jquery as $ to this self invoking function.

})(jQuery)

How do I fix Lightbox2 problems using $.noConflict()?