开发者

Returning a zend paginator object in ajax request, getting wrong url

I'm using Zend Paginator here, in an ajax request I am retrieving objects based upon search results and rendering the HTML and passing it along with a rendered Zend Paginator view.

The problem is that the returning paginator doesn't take into account the new url. for example if I were to do it without ajax I would have my page url read:

www.mysite.com/?search=something&page=2

However from and ajax query it doesn开发者_如何学运维't work that way the search variable is not appended to the url in the paginator links. Help please.


I assume you hava pagination links somewhere on your site that point to the different pages that are generated within you pagination.phtml file.

OnClick you need to get that href attribute and load the contents like that:

function getContents() {
    var url = window.location.protocol + "//" + 
              window.location.host + $(this).attr('href');

    var jqxhr = $.post(url, {
        "format" : "json"
    }, function(data) {
        displayContents(data);
    }, 'html');
    return false;
} 

$(document).ready(function() {
    $("#paginator a").each(function() {
        $(this).click(getContents);
    });
});

This way you get your classic url

www.mysite.com/?search=something&page=2

maybe you need to change the url field. Just alert the url field and look what needs to be changed.

Here is a tutorial on that (without search) : Zend Framework 1.9 tutorial 14: ajax requests part 1


Without seeing your code I can't be sure, but it sounds like your Paginator Controls View Scripts (i.e. the .phtml files which render your Next, Previous, etc links) is using the $this->url() but you haven't configured it to detect and append the search parameter onto the end of the links.

If your control view scripts are specific for that Paginator, try manually adding the "?search=something" in your <a> tag's href parameter. This should force it to include these in the output.

It would be great if you could provide us with the code from your Controller and View showing how you are implementing the Paginator and rendering the pages. Or a live Demo is always good :D

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜