title: Send data from js to servlet and get back the response
body: <p>I am a newbit to ajax and js.</p>
  
  <p>I have a simple jsp page with a html in it. I have an accompanying javascript file where I have defined all my functions. I have one such function to send some json data to servlet.
  <strong>I require help on retrieving back the response from servlet into the calling js file only.</strong></p>
  
  <p>I have the servlet up and running with post method as it receives the ajax call.</p>
  
  <p>Assume js file name is: First.js and servlet is FirstServlet.java</p>
  
  <p><strong>Javascript part to send the data from js to servlet:</strong></p>
  
  <pre><code>    var fullpath="contextpath/FirstServlet";
  
      //Sending the tradedata using ajax to the FirstServlet
      $.ajax({
          dataType: 'json',
          url: fullpath,
          type: 'POST',
          data: {jsonText:jsonText}
  
    });
  </code></pre>
  
  <p><strong>On the servlet side</strong> I do some modifications to the data and build a dynamic html
  The output of the servlet will be something like this added to a string variable.</p>
  
  <pre><code> &lt;div&gt;
     &lt;table&gt;
       &lt;tbody&gt;
          &lt;tr&gt;
             &lt;td&gt;
              &lt;input name="hi" value="hello" /&gt;
              &lt;/td&gt;
             &lt;td&gt;
              &lt;input name="bye" value="goodbye" /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
       &lt;/tbody&gt;
     &lt;/table&gt;
    &lt;/div&gt;
  </code></pre>
  
  <p>I want to return this tag back to the same javascript file that called it <strong>//Need solution for this part.</strong></p>
  
  <p><strong>End goal:</strong>
  I then want to append it to a div tag I have on the jsp file //I will use jquery to add this. This way I can refresh the div container without using iframe.</p>