Since getJSON() method is used to get JSON data using an AJAX HTTP GET request.
Which method to use to get data from doPost method in servlet.
Say that I have used action to send the data to the servlet and want to get the response ..
Which JSON method to use..An example or a good tutorial would help
Thanks:)
So, you’re basically asking how to get JSON data by a POST request?
Instead of
use
When you let the servlet do
response.setContentType("application/json"), then thedatais already in JSON format.However, after reading your question and the comments once more, I think you’re basically asking how to submit a POST form using jQuery. This has essentially nothing to do with JSON (although the servlet can return a JSON response if desired).
Assuming the following form
here’s how you can “ajaxify” it (do it during document ready!)
For another example also see this answer.
There exist plugins which do it more nicely, such as jQuery Form. It’s then as simple as
and it also supports
<input type="file">elements without much trouble.