title: How to catch a specific value from controller to JQuery?
body: <p>So I am working on a JQuery. When I press the submit button, data will be added to database and an alert box will appear and display the id of the new data. Here are some of the code</p>
  
  <pre><code>    $(function(){
      $('#submit').click(function()
      {       
          if{
            str = "some.htm?type=input&amp;memo="+$("#memo").val()+"&amp;description="+$("#description").val();                       
                               $.ajax({
  
                                  url : str,
                                  async : 'false',
                                  success : function (id)   
                                                              { alert("....."); // I want                    the alert to display the newID after the data are successfully inserted into database}
                                  }});  
                   }
     }});
  </code></pre>
  
  <p>and here is the controller</p>
  
  <pre><code>protected Object formBackingObject(HttpServletRequest request) throws ServletException {
      Something something = new Something();
          dbHelper db = new dbHelper();
  
  
          if(request.getParameter("type")!= null)
          {
              type = request.getParameter("type");
              String memo = request.getParameter("memo");
              String description = request.getParameter("description");
  
              if(type.equalsIgnoreCase("input") == true)
                  {
                  String newId = db.getCode("idSome", "vrs_somedatabase", "PYR"); //will return newest id from database
                  db.InsertSome(id, memo, description); //insert data into database, ignore it
  
                  }
          }    
          return iuom;
  
      }  
  </code></pre>
  
  <p>I have another method but it doesn't work too.. Here are the codes</p>
  
  <pre><code>$.post("some.htm", { memo: $("#memo").val(), description: $("#description").val() },
                                     function(id) {
                                       alert(....); // I want to display the newID after the data are successfully inserted into database
                                     }); 
  </code></pre>
  
  <p>and the controller </p>
  
  <pre><code>public ModelAndView onSubmit(Object command) throws Exception {
          inpt = (some) command;
  
              if
          {
              dbHelper db = new dbHelper();
              String newId = db.getCode("idSome", "vrs_somedatabase", "PYR"); //will return newest Id from database
              db.InsertSome(id, inpt.getMemo(), inpt.getdescription()); //insert into database, ignore it
          }
          ModelAndView model = new ModelAndView("someView","some","model");
          ModelAndView model = new ModelAndView("someView");
          model.addObject("newId",newId);
  
          return model;
  
  
      }
  </code></pre>
  
  <p>The question is, I can't display the newId.. How can I pass it from controller to JQuery?</p>
  
  <p>Edit : I found the answer</p>
  
  <p>I found the answer.. So basically, I create another view named temporer.jsp, it's function is just to help me storing the value</p>
  
  <pre><code>&lt;%@ include file="/WEB-INF/jsp/include.jsp" %&gt;
  &lt;%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %&gt;
  &lt;%@ page language="java" import="java.util.*"%&gt;
  &lt;%@ page language="java" import="java.text.*"%&gt;
  
  ${newId}
  </code></pre>
  
  <p>then I use this one</p>
  
  <pre><code>$.post("some.htm", { memo: $("#memo").val(), description: $("#description").val() },
                                     function(newId) {
                                       alert(newId);
                                     }); 
  
  public ModelAndView onSubmit(Object command) throws Exception {
          inpt = (InputPaymentTerm) command;
  
          ......
  
  
          ModelAndView model = new ModelAndView("temporer");
          model.addObject("newId",newId);
  
          return model;
  
      }
  </code></pre>