0

I found this code for the infinite scroll pagination but there is one problem. I can pass a variable from this page going to democontent.php

Could anyone help me with this one? What I need to do is to pass an ID from this code to democontent.php I can't figure out what I have been doing wrong.

<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
  • 'contentData': {} this passes data to the PHP file Commented Nov 12, 2012 at 15:37
  • @ManseUK how do you use this? say for example i have an id=39 and i have to pass this value to democontent.php who do i do that? Commented Nov 12, 2012 at 15:40
  • stackoverflow.com/a/13346715/572939 <- this shows you how Commented Nov 12, 2012 at 15:44
  • Sir @rory mcCrossan has got it right. thanks for the help sir. Commented Nov 12, 2012 at 15:46

2 Answers 2

2

You've got it right there in your question:

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

For example:

var id = 5;

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

Then in your PHP:

$id = $_POST['id']; // = 5
Sign up to request clarification or add additional context in comments.

1 Comment

sorry sir. it's that i can't read the way the code was written. thank you for the help
0

i use this javascript function to pass a variable from js to php. If you want to use ajax, then you can use this:

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();
}

hope it helps.

1 Comment

And all the javascript zealots wonder why people use jQuery for this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.