Home Onclick event of a certain page, perform POST action of other page
Reply: 2

Onclick event of a certain page, perform POST action of other page

jitendra
1#
jitendra Published in 2010-11-15 06:40:40Z

Let me explain my problem with a scenario:
I have webpages "A.jsp" and "B.jsp". "B.jsp" is a page with a form that requires input field, 'username' and on submission displays a certain page "C.jsp" with user-specific information. "A.jsp" has table with an element that would correspond to 'username' on "B.jsp". Onclick of a certain 'username' on "A.jsp", I want to be redirected to "C.jsp" with clicked username specific information.

How do I get it done?

I am using MVC framework. Only A.jsp and B.jsp are tied to controller, C.jsp is only a View. But, I believe that is less of an issue, since this seem to be more of a javascript question.

Using prototype javascript framework, I have tried the following:
redirectToC=function(pageurl){
var username=document.getElementById("user1").value;
url=pageurl; //I am using B.jsp as Pageurl
$j.ajax({ type: 'POST',
url: url, data: "username="+username,
success: function(request){
window.location=request;
}
});
}

madhurtanwani
2#
madhurtanwani Reply to 2010-11-15 07:08:27Z

Does C.jsp support only POST - or does it support GET requests as well?

  1. If it does, in the onClick of the 'username' link, set the location of the browser (i think document.location) to the URL of C.jsp with the username as a GET parameter. Since you are generating the A.jsp page dynamically, this URL can be embedded into the page at generation time
  2. If it does not, a bad hack i can think of is to implement the the table element with the username, as a hidden form element which is submitted via javascript when clicked - 'form'.submit()
Adeel Ansari
3#
Adeel Ansari Reply to 2010-11-15 07:46:59Z
<form id="showUserForm" action="/controller/showUser" method="POST">
    <input type="hidden" id="username" name="username">
</form>

..........

<a onclick="showUser('${users.userName}')" href="#"></a>

..........

<script type="text/javascript">
    function showUser(userName){
        document.getElementById("username").value = userName;
        document.getElementById("showUserForm").submit();
    }
</script>
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.336125 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO