Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php AJAX提要问题。。没有错误,没有警告,什么都没有_Php_Jquery_Html_Ajax - Fatal编程技术网

Php AJAX提要问题。。没有错误,没有警告,什么都没有

Php AJAX提要问题。。没有错误,没有警告,什么都没有,php,jquery,html,ajax,Php,Jquery,Html,Ajax,我在使用jQuery脚本时遇到问题。。 该脚本显示来自Mysql的帖子,并有一个AJAX div检查更多内容。。 现在来谈谈我的问题。代码应该能正常工作,但运行时我什么也得不到。。没有错误,没有通知,Mysql很好,但什么都没有。有人能发现错误吗。。或者任何可能导致这一切的事情 这是我的代码: <?php /* settings */ session_start(); $number_of_posts = 5; //5 posts will load at a time $_

我在使用jQuery脚本时遇到问题。。 该脚本显示来自Mysql的帖子,并有一个AJAX div检查更多内容。。 现在来谈谈我的问题。代码应该能正常工作,但运行时我什么也得不到。。没有错误,没有通知,Mysql很好,但什么都没有。有人能发现错误吗。。或者任何可能导致这一切的事情

这是我的代码:

 <?php
/* settings */  
session_start();  
$number_of_posts = 5; //5 posts will load at a time  
$_SESSION['posts_start'] = $_SESSION['posts_start'] ? $_SESSION['posts_start'] : $number_of_posts; //where we should start
    /* loading of stuff */
    if(isset($_GET['start'])) {
        /* spit out the posts within the desired range */
        echo get_posts($_GET['start'],$_GET['desiredPosts']);
        /* save the user's "spot", so to speak */
        $_SESSION['posts_start']+= $_GET['desiredPosts'];
        /* kill the page */
        die();
    }

    /* grab stuff */
    function get_posts($start = 0, $number_of_posts = 5) {
        /* connect to the db */
        $connection = mysql_connect('localhost','root','');
        mysql_select_db('draft2',$connection);
        $posts = array();
        /* get the posts */
        $query = "SELECT item_id, username, item_content FROM updates ORDER BY update_time DESC LIMIT $start,$number_of_posts" or die(mysql_error()); 

        $result = mysql_query($query);
        while($row = mysql_fetch_assoc($result)) {
            preg_match("/<p>(.*)<\/p>/",$row['item_content'],$matches);
            $row['item_content'] = strip_tags($matches[1]);
            $posts[] = $row;
        }
        /* return the posts in the JSON format */
        return json_encode($posts);
    }

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"  dir="ltr">
<head>



<style type="text/css">
   .style1 {
                                font-family: "Trebuchet MS", "Lucida Sans Unicode", "Lucida Grande", "Lucida Sans", Arial, sans-serif;
                                background-image: url('images/banner.gif');
                        }
                        .style2 {
                                font-size: x-small;
                                color: #62D7D7;
                        }
                        .style3 {
                                text-align: center;
                        }
                        .style5 {
                                font-size: 12px;
                                font-family: "lucida grande", "tahoma", "verdana", "arial", "sans-serif"
                        }
                .style6 {
    font-family: "lucida grande", "tahoma", "verdana", "arial", "sans-serif";
}
.style7 {
    text-align: left;
    font-size: x-small;
    font-family: "Trebuchet MS", "Lucida Sans Unicode", "Lucida Grande", "Lucida Sans", Arial, sans-serif;
    color: #0070B8;
}

        #load-more                  { background-color:#eee; color:#999; font-weight:bold; text-align:center; padding:10px 0; cursor:pointer; }
        #load-more:hover            { color:#666; }
        .activate                   { background:url(loadmorespinner.gif) 140px 9px no-repeat #eee; }

                </style>




    <script type="text/javascript" src="jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="jquery.scrollTo-1.4.2.js"></script>
    <script type="text/javascript">
        //when the DOM is ready
        $(document).ready(function(){
            //settings on top
            var domain = 'http://davidwalsh.name/';
            var initialPosts = <?php echo get_posts(0,$_SESSION['posts_start']); ?>;
            //function that creates posts
            var postHandler = function(postsJSON) {
                $.each(postsJSON,function(i,post) {
                    //post url
                    var postURL = '' + domain + post.post_name;
                    var id = 'post-' + post.ID;
                    //create the HTML
                    $('<div></div>')
                    .addClass('post')
                    .attr('id',id)
                    //generate the HTML
                                //generate the HTML
                    .html('     <td class=\"style1\" colspan=\"2\" >&nbsp;<span class=\"style6\">' + post.username + '<\/span>"');
                    .html('                             <span class=\"style2\">NAME<\/span><\/td><\/tr><tr>');
                    .html('                                <td class=\"style3\" style=\"width: 67px\">Thumnail<\/td>');
                    .html('                                <td class=\"style5\"><p class="item_content">' + post.item_content + '<\/td><\/tr><tr>');
                    .html('                                <td class=\"style7\" colspan=\"2\">&nbsp;Respond (244) Like (12)<\/td><\/tr><tr>');
                    .html('                                <td class=\"style7\" colspan=\"2\">&nbsp;<\/td>');
                    .html('                                <\/table>');
                    .html('                      ');
                    .html('');
                    })

                    //inject into the container
                    .appendTo($('#posts'))
                    .hide()
                    .slideDown(250,function() {
                        if(i == 0) {
                            $.scrollTo($('div#' + id));
                        }
                    });
                }); 
            };
            //place the initial posts in the page
            postHandler(initialPosts);
            //first, take care of the "load more"
            //when someone clicks on the "load more" DIV
            var start = <?php echo $_SESSION['posts_start']; ?>;
            var desiredPosts = <?php echo $number_of_posts; ?>;
            var loadMore = $('#load-more');
            //load event / ajax
            loadMore.click(function(){
                //add the activate class and change the message
                loadMore.addClass('activate').text('Loading...');
                //begin the ajax attempt
                $.ajax({
                    url: 'jquery-version.php',
                    data: {
                        'start': start,
                        'desiredPosts': desiredPosts
                    },
                    type: 'get',
                    dataType: 'json',
                    cache: false,
                    success: function(responseJSON) {
                        //reset the message
                        loadMore.text('Load More');
                        //increment the current status
                        start += desiredPosts;
                        //add in the new posts
                        postHandler(responseJSON);
                    },
                    //failure class
                    error: function() {
                        //reset the message
                        loadMore.text('Oops! Try Again.');
                    },
                    //complete event
                    complete: function() {
                        //remove the spinner
                        loadMore.removeClass('activate');
                    }
                });
            });
        });
    </script>
</head>
<body>

    <!-- Widget XHTML Starts Here -->
    <div id="posts-container">
        <!-- Posts go inside this DIV -->
        <div id="posts"></div>
        <!-- Load More "Link" -->
        <div id="load-more">Load More</div>
    </div>
    <!-- Widget XHTML Ends Here -->

</body>
</html>

var域=”http://davidwalsh.name/';


在这里,我不知道这是否是您的工作站点,事实是:除了您的工作站点之外,您不能使用AJAX发布到其他站点。这是出于安全原因。

除了扫描代码之外,我没有做任何事情,但这行肯定需要更新吗<代码>变量域=http://davidwalsh.name/';
你能给我们提供更多关于bug的细节吗(你的ajax请求可以吗?它返回了什么?等等)(顺便说一句@thirtydot这个变量是未使用的)如果你看一下代码,你会注意到这个变量是未使用的。