title: not able to send form data through ajax via json object
body: <p>I am trying to send json data through ajax in jersey api . however i am not able to send the data. Here is my code:</p>
  
  <h3>javascript code</h3>
  
  <pre><code>var jsonObj = createDataObj();
  
      $.ajax({    
                  type : "POST",
                  url : "/api/orders/addOrder",
                  data : jsonObj ,
                  contentType: "application/json",
                   error: function (xhr, ajaxOptions, thrownError) {
                          alert(thrownError);
                        }
                  })
                    .done(function( response ) {
                       if(response.isSaved){
                           alert("Your order has been placed successfully &amp; order id is "+response.orderId);
                       }
                       else{
                           alert("Soming went wrong. Please try again.");
                       }
                    });   
  
  
  //creating json object    
  
  function createDataObj(){
          var dataObj = "" + "{" + '"customerId":'+ $('#custId').val()+','+ '"companyName":'+'"'+$("#companyKey").val()+'",'
              + '"street" : '+'"'+$("#streetKey").val()+'",'+'"postalCode" : '+'"'+$("#postalCodeKey").val()+'",'+
              '"city":'+'"'+$("#cityKey").val()+'",' + '"country":'+'"'+$("#countryKey").val()+'",' 
              + '"productId":"'+  $("#product").val())+'",' +  '"quantity":'+ $('#quantity').val() + "} ";
          return dataObj;
  
      }
  </code></pre>
  
  <h3>and jersey class</h3>
  
  <pre><code>package elisa.devtest.endtoend;
  
  import java.util.Collection;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  
  import javax.ws.rs.Consumes;
  import javax.ws.rs.GET;
  import javax.ws.rs.POST;
  import javax.ws.rs.Path;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.MediaType;
  
  import elisa.devtest.endtoend.dao.OrderDao;
  import elisa.devtest.endtoend.model.Customer;
  import elisa.devtest.endtoend.model.DataDto;
  import elisa.devtest.endtoend.model.Order;
  
  @Path("/orders")
  public class OrderResource {
  
      private static final Logger log = Logger.getLogger(OrderResource.class
              .getName());
  
      @GET
      @Produces(MediaType.APPLICATION_JSON)
      public Collection&lt;Order&gt; getOrders() {
          return new OrderDao().findOrders();
      }
  
      /**
       * @param name
       * @param company
       * @param Country
       * @param cityKey
       * @param postalCodeKey
       * @param Street
       * @param product
       * @param quant
       * @return Method addByPassingValue method used to fetch the data from form
       *         and sent it DAO for insertion in database. This Method is called
       *         when submit button is clicked on form
       */
      @POST
      @Path("/addOrder")
      @Produces(MediaType.APPLICATION_JSON)
      @Consumes(MediaType.APPLICATION_JSON)
      public String addByPassingValue(DataDto obj) {
          StringBuilder response = new StringBuilder();
          try{
  
          log.log(Level.SEVERE, "OrderResource", "Processing records");
  
          response.append("success");
  
          Customer cust = new Customer(2, "test", "test",
                  "test", "test", "test");
  
      //  Customer cust = new Customer(Integer.parseInt(custId), company, Street,
          //      postalCodeKey, cityKey, Country);
      //  new OrderService().addOrder(obj.getCustomer(), "f3DFS234#212dfS", 3);
  
          return response.toString();
          }   catch(IllegalArgumentException e){
              e.printStackTrace();
              return response.append("{\"isSaved\":").append(false).append("}").toString();
  
          }
          catch(Exception e){
              e.printStackTrace();
              return response.append("{\"isSaved\":").append(false).append("}").toString();
          }
  
  
      }
  
  
  }
  
  where DataDto has setter and getter method
  
  problem is I am not able to call method through ajax call
  
  please help 
  thanks in advance
  </code></pre>