aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Doing a POST in jsp without leaving the page and displaying a success text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Doing a POST in jsp without leaving the page and displaying a success text" Watch "Doing a POST in jsp without leaving the page and displaying a success text" New topic
Author

Doing a POST in jsp without leaving the page and displaying a success text

Vivek K Jain
Greenhorn

Joined: Mar 17, 2013
Posts: 19

ok i have found a thread on coderanch corresponding my query but this is an extension to the solution provided there.

Firstly i want to know what are the possible ways of doing it(form submission without leaving the page..).

Secondly i have tried using AJAX(as replied by Bear sir there) for doing that , & i did get success in inserting value in database but i want to store some more information to same database by using the arguments provided in the url parameter.how could i pass more arguments to the url parameter of open() of the XmlHttpRequestObject ?
here what i did : i tried two syntax
1.

2.

tell me which one is correct because using the no.2 syntax i am getting only the first argument (content) value to my PostResAjax servlet (which is controlling database insertion), other field in the db are written as "undefined".Do i need to also encode uri components?(i didn't for the content field though it had spaces)?? if so how?
Also, here content,cname,userid all are ids defined in my jsp, how can i pass arguments to the ajax calling function(the onclick func for the post button) with EL syntax like ${userid} etc.

please correct me if there's something conceptual wrong like inserting in database using ajax or something like that.
i just want to simulate an "add comment" type of feature as provided in most blogspots.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

This has nothing at all to do with JSP, so it's been moved to a more appropriate forum.

Building up URL to Ajax "by hand" is not recommended. The values need to be encoded, and there are other nuances.

It is highly recommended to use jQuery to make Ajax calls. It will take care of all those problems and vastly simplify the code.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
There is no difference between 1 and 2!, You just changed string concatenation. The name of the serverside resource implies you want a Post request, but you are sending a get. You are not encoding the url valies
Vivek K Jain
Greenhorn

Joined: Mar 17, 2013
Posts: 19


id=writeRes is my button which make comment field visible i.e. the textarea id=cresponse nd rest is i hope clear...
this is what i did sir using your suggestion of jquery...everything is working fine upto $.ajax() function it is simply i think not invoking my servlet..(PostResAjax)...why?
do i have to have some returning code in servlet which returns back me to the jsp page again.
also is the encoding part which both of you above mentioned is being handled by jquery?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doing a POST in jsp without leaving the page and displaying a success text