How do I add another JSP page to a <div> when I click a link?

I have two different sections on the JSP page. One contains a menu of links, when you click div2 (id-content) loads different pages, respectively. I'm doing something like -

<div id="menu">
<ul class="navbar">
  <li><a name="login" href="Login.jsp" onclick="changeContent()">Login</a>
   </li></div>

and in the script I have something like -

<script language="JavaScript">
function changeContent() {
    document.getElementById('content').load('Login.jsp');
}
</script>

I also tried -

document.getElementById('content').innerHTML=
"<jsp:include page="Login.jsp">"; 

None of the methods worked. Please suggest how I should

+5
source share
4 answers

Try jquery ..

function changeContent() {
    $('#content').load('Login.jsp');
}
+4
source

The solution is to use Ajax, which will asynchronously retrieve the contents of your page, which can be inserted using the innerHTML method. See my answer to a similar question about how the Ajax call and some introductory links work.

, , Element load() ( ). , , , - javascript.

FYI, javascript - , , <script> </script> . , . , innerHTML. javascript HTML, , HTML javascript.

+1

jquery. . $('#content').load(your_url);. , load(url, function() { ...}). http://api.jquery.com/load/

0

. . ( ) , div HTML. AJAX. , AJAX , POST ( ) . Ajax HTML . , AJAX, .

0

All Articles