2

I want to update the contents/portlets of my pages, without reloading the whole page.

enter image description here

I tried using jQuery .load() in navigation.ftl:

<script type="text/javascript">
    $(document).ready(function(){
        $("nav#navigation ul li a").click(function(){
            var page = $(this).attr("href");
            $("#content").load(page);
        });
    });
</script>

I added e.preventDefault() to prevent the default functionality from occurring as suggested by Sudakatux and It works but this does not resolve my problem, because the entire page (including head and body) is wrapped inside the div#content each time I click on a menu (see the screenshot below).

The page is repeated inside the div #content

Mustapha Aoussar
  • 5,833
  • 15
  • 62
  • 107
  • Possible duplicate of [How to stop default link click behavior with jQuery](http://stackoverflow.com/questions/5632031/how-to-stop-default-link-click-behavior-with-jquery) – Tobias Liefke Oct 27 '15 at 23:01

1 Answers1

4

This is not a Liferay question. You are missing the preventDefault() since you are using a link:

<script type="text/javascript">
    $(document).ready(function(){
        $("nav#navigation ul li a").click(function(e){
            e.preventDefault(); //You are missing this line
            var page = $(this).attr("href");
            $("#content").load(page);
        });
    });
</script>

If you used a button (not submit) this wouldnt happen. Meaning is not really 'Liferay's fault'

Marco Mercuri
  • 1,117
  • 9
  • 17
jstuartmilne
  • 4,398
  • 1
  • 20
  • 30
  • Thank you so much! it works, but the entire page (including head and body) is wrapped inside the `div#content`, so when I click on a menu I get two headers and two footers. – Mustapha Aoussar Nov 14 '15 at 15:06
  • thats because you are loading the entire page. not the portlet jsp. what you need is the url of the jsp you can get that by doing something like this `````` and then in a javascript delcare a var with its value ```var p = '<%= onCancelURL %>' ``` then load in ```$('#content').load(p)``` hope it helps – jstuartmilne Nov 15 '15 at 16:04