0
<script type='text/javascript' src='js/jquery.js'></script>

<script type="text/javascript">
    $(document).ready(function() {
        $("#gt").click(function() {

            $("#internal").load('second.jsp');   //not working....
            alert("loaded");

        });
    });
</script>


    Happy new year...................
    <a href="#" id="gt"> Click me </a>

    <p id="para"></p>

    <div id="internal"> a</div>

I am working in eclipse with Liferay 6.1. JQuery is working properly...i am able to change innerHTML of divisions and alert box also coming.. But not able to load page inside the div. The same code is working properly in simple Dynamic web project. Can any body help me pls...

Boat
  • 515
  • 2
  • 8
  • 28
  • 3
    inspect the request in a browser console and see what data is returned (if any) and status of request Your alert is meaningless as `load()` is AJAX which is asynchronous. Console will also show if request is even being made – charlietfl Jan 02 '13 at 06:40
  • What `version of jquery` you are using? – Jai Jan 02 '13 at 07:22
  • jQuery JavaScript Library v1.8.3. It is possible to do <%@include file="second.jsp" %>. But if i am trying to load using javascript, it is not coming...nd not showing any error. – Boat Jan 02 '13 at 10:07

3 Answers3

3

Make sure your second.jsp is available to your webbrowser: You are in a portlet environment, thus you cannot assume that ./second.jsp is referring to the same directory as the jsp is in that is serving the content you pasted in your question. Most likely you'll need a different path - if your jsp is in /WEB-INF, you'll even need to move it somewhere else, so that it can be dynamically requested.

Further, if second.jsp needs access to the portal session, you'd better use a resource-request to your portlet. <portlet:resourceURL/> will be your friend for this.

As charlietfl suggests in the comment to your question, the best way is to use an HTTP-level output in your browser (e.g. firebug) and see what kind of request is actually sent.

Also, as you're in a portal environment, you may want to append/prepend <portlet:namespace/> to the id you're giving - otherwise you'll have duplicate ids when your portlet is added to the page twice (or someone else chooses to use the same id)

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
  • But if i am including like <%@include file="second.jsp" %> , it is working perfectly... – Boat Jan 02 '13 at 09:28
  • If it is working properly if i am including second.jsp, why is it not getting while loading using javascript? – Boat Jan 02 '13 at 09:39
  • 1
    @Shibu Kindly understand the difference between `<%@include >` and the `${#divId}.load()`. The former is a static include i.e. during compile time and the later is a request to the server and server would send the __content__ of the JSP as a response. So as mentioned you would need to use `` which would call the `serveResource` method and deliver the __content__ of the JSP instead of the JSP. So `<%@include >` includes the JSP and while the `${#divId}.load()` loads the __content__ of the JSP sent by the server. – Prakash K Jan 02 '13 at 11:11
  • What @PrakashK says: +1 - nothing to add. – Olaf Kock Jan 02 '13 at 11:12
  • I am sorry to say that, i dnt kno hwo to use here. can u pls paste the code? – Boat Jan 02 '13 at 11:43
  • 2
    Check the answer to http://stackoverflow.com/questions/7241861 (I don't have enough time at hand to post copyable code) - also you should really read about the portlet resource phase and understand the difference between portlet and servlet development, you're currently falling into that trap. The portlet specification (jsr-286) might be a bit dry, but contains a lot of information. Otherwise, https://www.liferay.com/documentation/liferay-portal/6.1/development may be fore you, "Liferay in Action" (book) another resource. Read/learn this before you get deeper into development! – Olaf Kock Jan 02 '13 at 11:57
0

u have not specified any callback function to be called after load.

$('#reinternalult').load('second.jsp', function() {
  alert('Load was performed.');
});

make sure the path of second.jsp is correct and it properly outputs the html

also try to call second.jsp directly from browser and see what you get

Arun Killu
  • 13,581
  • 5
  • 34
  • 61
  • But the code i pasted was working in dynamic web project. I tried the code which you given..but no change, the second.jsp is not loading in the division in liferay. – Boat Jan 02 '13 at 06:36
  • callback won't make the ajax load if it's not working in the first place and the callback is optional – charlietfl Jan 02 '13 at 06:38
  • @charlietfl now he can make confirm that alert comes only after the ajax is success – Arun Killu Jan 02 '13 at 06:39
  • Ok. But why in lifeary portlet it is not working..... I have done as you said, but still it is not working... – Boat Jan 02 '13 at 06:41
  • No error in the console and the path is correct.. Have you tried this in Liferay? – Boat Jan 02 '13 at 06:47
0

Also use the .on() method instead of .click() method. This will save you from DOM bloat

$(document).ready(function() { $('body').on('click','#gt',function() {

        $("#internal").load('second.jsp', function(){
              alert("loaded");
        });
     });

});

etnlbck
  • 9
  • 2