0

無限スクロールページ付けのこのコードを見つけましたが、1つの問題があります。このページからdemocontent.phpに変数を渡すことができます

誰かがこれを手伝ってくれませんか?私がする必要があるのは、このコードからdemocontent.phpにIDを渡すことです。私が間違っていることを理解することはできません。

<script type="text/javascript">

$(function(){   
    $('#content').scrollPagination({    
        'contentPage': 'democontent.php', // the page where you are searching for results
        'contentData': {}, // you can pass the children().size() to know where is the pagination
        'scrollTarget': $(window), // who gonna scroll? in this example, the full window
        'heightOffset': 10, // how many pixels before reaching end of the page would loading start? positives numbers only please
        'beforeLoad': function(){ // before load, some function, maybe display a preloader div
            $('#loading').fadeIn(); 
        },
        'afterLoad': function(elementsLoaded){ // after loading, some function to animate results and hide a preloader div
             $('#loading').fadeOut();
             var i = 0;
             $(elementsLoaded).fadeInWithDelay();
             if ($('#content').children().size() > 0){ // if more than 100 results loaded stop pagination (only for test)
                $('#nomoreresults').fadeIn();
                $('#content').stopScrollPagination();
             }
        }
    });

    // code for fade in element by element with delay
    $.fn.fadeInWithDelay = function(){
        var delay = 0;
        return this.each(function(){
            $(this).delay(delay).animate({opacity:1}, 200);
            delay += 100;
        });
    };

});
</script>
4

2 に答える 2

2

あなたはあなたの質問にそれを持っています:

'contentData': {}, // you can pass the children().size() to know where is the pagination

例えば:

var id = 5;

$('#content').scrollPagination({  
    // other settings
    contentData: { id: id }
});

次に、PHP で次のようにします。

$id = $_POST['id']; // = 5
于 2012-11-12T15:39:37.217 に答える
0

このjavascript関数を使用して、jsからphpに変数を渡します。ajaxを使用する場合は、次を使用できます。

function showUser()
{
    var combo = document.getElementById("users");
    var uname = combo.options[combo.selectedIndex].value;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById("selectbox2").innerHTML=xmlhttp.responseText;
        }
    }

    xmlhttp.open("GET","getuser.php?q="+uname,true);
    xmlhttp.send();
}

それが役に立てば幸い。

于 2012-11-12T15:45:56.983 に答える