1

I've made an Ajax script that only loads (that's the plan) the content of the pages. The thing is it still reloads the whole layout, along with the views. How can I make it so it doesn't rerender when it already exists ? My Ajax:

$(document).ready(function() {
    $('.navigation li a').click(function() {
        var toLoad = $(this).attr('href');
        $('#content').hide('fast', loadContent);
        window.location = $(this).attr('href');
        function loadContent() {
            $('#content').load(toLoad, '', showNewContent())
        }

        function showNewContent() {
            $('#content').show('normal');
        }

        return false;
    });
});
Denki
  • 363
  • 2
  • 14

1 Answers1

0

Wasn't sure based on your question, but does your AJAX code sit in a view?

This is a tricky one but I'd try this: in your given controller, you'd want to use a Zend-specific method call. Found this here at SO, it may apply. Zend Framework - Set No Layout for Controller

If you've already tried something similar to the above, perhaps this Zend Framework2 link would be of service: Zend Framework 2: Auto disable layout for ajax calls

Community
  • 1
  • 1
Adam T
  • 675
  • 8
  • 22
  • I call it in the layout script. I know it works because it does the hiding animation. – Denki Jun 01 '15 at 16:46
  • Were you able to do any disabling for this in the controller? – Adam T Jun 01 '15 at 16:50
  • Ok. Also I noticed that the jQuery document.ready - inside there has a call to `window.location` and I'm not 100% sure - but it may be causing a reload that you speak of. – Adam T Jun 01 '15 at 16:52
  • Perhaps try commenting out 1 or 2 lines of the ajax stuff (the window.location call might be causing the other functions to not get reached? Is there anything else happening based on your recent changes? Lastly - I'd maybe try doing the AJAX stuff in a view and not a layout - since you're calling methods that disable layouts – Adam T Jun 01 '15 at 17:39
  • 1
    I deleted all that crap and just wrote `$('a').click(function() { var toLoad = $(this).attr('href'); $('#content').load(toLoad);` while adding a `setTerminal();` to all my controllers and it worked! The only problem now is that the URL stays the same, no matter the content, so I have to fix that somehow. – Denki Jun 01 '15 at 17:42