title: How do I capture the servlet response in the jQuery post method?
body: <p>I would like to validate the post response text which is returning from servlet and display in the top of the page without any redirection. Here is the piece of code developed to achieve the same only for form submission. </p>
  
  <p><strong>Working code:</strong></p>
  
  <pre><code>$('#btnSubmit').click(function () {
      var data = $('#formQuestion').serialize();
      $.post('/reports/htm/submit.do', data);
      confirmationPage();
  });
  </code></pre>
  
  <p>In the above code, my request parameters are filled with form data. </p>
  
  <p>I enhanced the code to display the bar with status. But, the enhanced code is not working. I am unable to figure it. Please help.</p>
  
  <p><strong>Not working code:</strong></p>
  
  <pre><code>$('#btnSubmit').click(function () {
      var data = $('#formQuestion').serialize();
      $.post('/reports/htm/submit.do', function (data, status) {
          if (status === "Success") {
              alert(status);
              $('#message').css("display", "block");
              $('#message').css("background-color", "green");
              $('#message').text('Form Submission Success.');
          } else {
              alert(status);
              $('#message').css("display", "block");
              $('#message').css("background-color", "red");
              $('#message').text('Form Submission Failed.');
          }
          confirmationPage();
      });
  });
  </code></pre>
  
  <p>In the above code, my request parameters are empty. I could not figure it what is an issue here?</p>
  
  <p><strong>Alternative Solutions Tried:</strong></p>
  
  <p><em>Working with Redirection</em></p>
  
  <pre><code>$('#btnSubmit').click(function () {
                  $.ajax({
                      type: 'POST',
                      data: $('#formQuestion').serialize(),
                      url: '/reports/htm/submit.do',
                      success: function (data) {
                          $('#message').css("display", "block");
                          $('#message').css("background-color", "green");
                          $('#message').text('Form Submission Success.');
                      },
                      error: function () {
                          $('#message').css("display", "block");
                          $('#message').css("background-color", "red");
                          $('#message').text('Form Submission Failed.');
                      }
                  });
              });
  </code></pre>
  
  <p><strong>Servlet Response:</strong></p>
  
  <p>Success and Failed</p>