Tuesday, April 24, 2012

Re: Ajax Pagination only works once (no javascript loaded)

This works for me:

$(function()
{
initPagination();
});


function initPagination()
{
$('div.PaginationLinks a').live('click', function(ev)
{
ev.preventDefault();

$('#content').loading(); // show spinner

// closest() includes current element
var $container = $(this).closest('div.PaginationLinks').parent('div');
var s_top = $container.offset().top;

$.ajax({
url: $(this).attr('href'),
dataType: 'html',
success: function(data, textStatus, XMLHttpRequest)
{
var $data = $(data).fadeTo(0, 0.1);

$('#content').loading(false); // remove spinner

$container.animate(
{ opacity: 0.1 },
500,
function()
{
// why doesn't replaceWith() return the new element?!?
$container.replaceWith($data);

// scroll back up
$data.animate(
{opacity:1},
500,
function()
{
$('html, body').animate({ scrollTop: s_top }, 'slow', 'swing');
}
);
}
);
},
error: function(XMLHttpRequest, textStatus, errorThrown)
{
alert(textStatus);
}
});
});
}

On Tue, Apr 24, 2012 at 5:08 AM, Timo Respondek
<timo.respondek89@googlemail.com> wrote:
> Update:
>
> After some questioning in the #cakephp irc channel I've found out or rather
> was pointed to the fact that I'd need to rebind my javascript functions.
> I've done so for other divs that are loaded into the current dom, but how
> would I go about this for my pagination? The links that are created by the
> PaginatorHelper when using Ajax look like this:
>
> $("#link-1983047312").bind("click", function (event)
> {$.ajax({dataType:"html", evalScripts:true, success:function (data,
> textStatus) {$("#tableWrap").html(data);},
> url:"\/companies\/index\/page:1"});
>
> Inside a $(document).ready block at the end of the page. Or rather the links
> should be bound by live() instead of bind(), is there an easy way to do this
> or, alternatively, can someone kindly point me to a Ajax Pagination example
> viable for Cake 2.1?
>
>
> Thanks in advance again
>
>
>
> Timo
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscribe@googlegroups.com For more options, visit this group at
> http://groups.google.com/group/cake-php

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate