Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4615556
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:51:25+00:00 2026-05-22T01:51:25+00:00

Since getJSON() method is used to get JSON data using an AJAX HTTP GET

  • 0

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:)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:51:25+00:00Added an answer on May 22, 2026 at 1:51 am

    So, you’re basically asking how to get JSON data by a POST request?

    Instead of

    $.getJSON('servleturl', function(data) {
        alert(data);
    });
    

    use

    $.post('servleturl', function(data) {
        alert(data);
    });
    

    When you let the servlet do response.setContentType("application/json"), then the data is 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

    <form id="formid" action="servleturl" method="post">
        <input type="text" name="foo" />
        <input type="text" name="bar" />
        <input type="submit" />
    </form>
    

    here’s how you can “ajaxify” it (do it during document ready!)

    $('#formid').submit(function() {
        $form = $(this);
        $.post($form.attr('action'), $form.serialize(), function(data) {
            // Do something with response. Display message? Redirect to other page?
            alert(data);
        });
    });
    

    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

    $('#formid').ajaxForm(function(data) {
        // Do something with response. Display message? Redirect to other page?
        alert(data);
    });
    

    and it also supports <input type="file"> elements without much trouble.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating this script which loads the data from JSON which is encoded in
I'm using jQuery's $.getJSON() API to retrieve data from a given URL for a
I'm trying to load data from an external .js file, containing a JSON representation
Since I'm used to developing in Java, I'm familiar with what files get generated
Since I'm using Java 1.4.2, this means that I cannot use Java's implementation of
I'm trying to grab some data from facebook, and since it is a pretty
I need to get value from json. It works perfectly on returned objects, but
Since Graduating from a very small school in 2006 with a badly shaped &
Since the keyboard is the interface we use to the computer, I've always thought
Since the only operations required for a container to be used in a stack

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.