如何将ID发送到控制器?

时间:2014-09-05 17:27:06

标签: javascript php jquery

我想向我的PHP控制器发送一个id。只有我不能一起发送ID。 to fetch_pages.php。这里的任何人都可以帮助我吗?

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

    var track_click = 0; //track user click on "load more" button, righ now it is 0 click
    var total_pages = <?php echo $row_count; ?>;
    $('#results').load("fetch_pages.php", {'page':track_click}, function() {track_click++;}); //initial data to load

    $(".load_more").click(function (e) { //user clicks on button

        $(this).hide(); //hide load more button on click
        $('.animation_image').show(); //show loading image

        if(track_click <= total_pages) //make sure user clicks are still less than total pages
        {
            //post page number and load returned data into result element
            $.post('fetch_pages.php',{'page': track_click}, function(data) {

                $(".load_more").show(); //bring back load more button

                $("#results").append(data); //append data received from server

                //scroll page to button element
                $("html, body").animate({scrollTop: $("#load_more_button").offset().top}, 500);

                //hide loading image
                $('.animation_image').hide(); //hide loading image once data is received

                track_click++; //user click increment on load button

            }).fail(function(xhr, ajaxOptions, thrownError) { 
                alert(thrownError); //alert any HTTP error
                $(".load_more").show(); //bring back load more button
                $('.animation_image').hide(); //hide loading image once data is received
            });

            if(track_click >= total_pages-1)
            {
                //reached end of the page yet? disable load button
                $(".load_more").attr("disabled", "disabled");
            }
         }

        });
});
</script>

1 个答案:

答案 0 :(得分:0)

如果我理解你的问题,那么

$.post('fetch_pages.php',{'page': track_click}

应该像

$.post('fetch_pages.php',{'page': track_click, 'id': <?php echo $id; ?> }