Shile
Shile

Reputation: 57

Dynamic Divs in jsp

I'm trying to create a page that will be rendered in steps. A user selects a certain option and the next div is dynamically rendered on the jsp page depending on the values selected. for example

MyPage.jsp

<input type="button" onclick="somejsfunction();" value="Select Choice" />

somejsfunction() issues a POST to the server and sets some values in the session. I then need to render a div in MyPage.jsp. I'm thinking i could always just spit out the HTML code from the post call and then append it to the document body in somejsfunction() but i was wondering if there is a cleaner way to do this? Thanks

Upvotes: 0

Views: 1249

Answers (1)

Jigar Joshi
Jigar Joshi

Reputation: 240870

It is much cleaner with jQuery

function callMe(){
    $.ajax({
      type: "POST",
      url: "/someServlet",
      data: { methodToInvoke: "sayHello" , data: "Abc" }
    }).done(function( msg ) {
      //msg is the HTML received from server
      $("#someDivId").html(msg);
    });
}

Upvotes: 1

Related Questions