replace div content using ajax and jquery

Your code has a function which defines an onclick action and doesn’t make the call itself. I bet if you double clicked the link it would work, but you should do it like this:

function MakeRequest(id)
{
    $.ajax({
        url : 'display.php',
        data:{"id":id},
        type: 'GET',

        success: function(data){
            $('#ResponseDiv').html(data);
        }
    });
}

Finally, change the call to this:

onclick='MakeRequest(5);'

OR just do this, which binds the li element to the click function and no “onclick” is necessary:

$(document).ready(function()
{
    $("#page_num li").click(function() {
       var id=$(this).attr(id);
        $.ajax({
        url : 'display.php',
        data:{"id":id},
        success: function(data){
            $('#ResponseDiv').html(data);
        }
    });
});
});

Leave a Comment