JQuery.load issue

I have a web page with search form fields and on a submit button click I make an Ajax call and fill a div with results using Ajax.BeginForm

The results contain paging links for paging processing.

Problem after Ajax call I have this JQuery code that should fire when one of the paging links is clicked. But they don't shoot.

Is it because the div is being filled with an Ajax call?

I tested this code with submit button click and it works fine. Only paging links fail.

    $('.pagerlinks a').click(function() {
       $('#resultsdiv').load('Search/Advanced', {Keywords=keywords, etc }); 
});

      

0


a source to share


3 answers


Another way to do it is to restore the callback function called the $.load

second parameter:



function initPagerlinks()
{
     $('.pagerlinks a').click(function() {
           $('#resultsdiv').load('Search/Advanced', {Keywords=keywords, etc }, initPagerlinks); 
     });
}

$(document).ready(function() {
    initPagerlinks();
});

      

+2


a source


I would use the bind function in jquery to bind to all specified elements at any time of creation:

http://docs.jquery.com/Events/live



Also does your code light up on the DOM ready event? how in:

$(function () {
 $('.pagerlinks a').click(function() {
       $('#resultsdiv').load('Search/Advanced', {Keywords=keywords, etc }); 
});

});

      

+3


a source


There are two solutions: 1. Add a callback function to the upload function that sets up events on the loaded content. 2. Use live events:

$("p").live("click", function(){ $(this).after("Another paragraph!"); });

http://docs.jquery.com/Events/live

0


a source







All Articles