title: How to send data in json format in jquery ajax for restfull web services
body: <p>I am sending the json format data in jquery ajax for restful web services but It is not sending. I am new in web technology, so please help me. I write the script for sending the JSON data using following link
  <a href="https://stackoverflow.com/questions/19557184/how-to-pass-json-data-to-restful-web-services-through-ajax-and-also-how-to-get-j">how to pass JSON data to restful web services through ajax and also how to get JSON data?</a></p>
  
  <p><strong>My javascript code is</strong></p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
   $(document).ready(function(){           
       $('#btnBooking').click(function(){  
               var serviceCategory=document.getElementById("services").value;
               var availDate=document.getElementById("scheduledDate").value;
               var custName=document.getElementById("userName").value;     
               var custMobile=document.getElementById("userContactNumber").value;  
               var custEmail=document.getElementById("addressemailId").value;
               var custAddress=document.getElementById("address1").value;
               var JSONObject= {"serviceCategory":serviceCategory, "availDate":availDate, "custName":custName, "custMobile":custMobile, "custEmail":custEmail, "custAddress":custAddress};
               var jsonData = JSON.stringify( JSONObject );
               $.ajax({
                   url: "http://localhost:8080/HomeServiceProvider/rest/booking/saveBookingDetails",
                   type: "POST",
                   dataType: "json",                  
                   data: jsonData,
                   contentType: "application/json",
                   success: function(response){
                      alert(JSON.stringify(response));
                   },
                   error: function(err){
                      alert(JSON.stringify(err));
                   }
              });     
       });  
  }); 
  
  
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>My Html code is</strong></p>
  
  <pre><code>&lt;form class="form-horizontal" id="scheduleLaterForm" name="scheduleLaterForm" action="#" method="post"&gt;
      &lt;div class="col-lg-8"&gt;
          &lt;div class="alert alert-danger alert-dismissable" style="display: none;" id="errorMessageDiv"&gt;Error
                  Message Goes Here&lt;/div&gt;                                     
          &lt;div class="form-group"&gt;
                      &lt;label class="col-lg-3 control-label"&gt;Name:&lt;font style="color: red;"&gt;*&lt;/font&gt;&lt;/label&gt;
                      &lt;div class="col-lg-9"&gt;
                          &lt;input class="form-control" id="userName" name="userName" placeholder="Full Name" value="" type="text"&gt;
                      &lt;/div&gt;
          &lt;/div&gt;                          
  
          &lt;div class="form-group"&gt;
              &lt;label class="col-lg-3 control-label"&gt;Services:&lt;/label&gt;
              &lt;div class="col-lg-9"&gt;
                  &lt;select class="form-control" id="services" name="subService"&gt;
                      &lt;option&gt;Select Service&lt;/option&gt; 
                      &lt;option value="1"&gt;Carpenter&lt;/option&gt;    
                      &lt;option value="2"&gt;Mobile SIM services&lt;/option&gt;  
                  &lt;/select&gt;
              &lt;/div&gt;
          &lt;/div&gt;                                  
  
          &lt;div class="form-group"&gt;
              &lt;label for="schedule-tme" class="col-lg-3 control-label"&gt;Schedule Date:&lt;font style="color: red;"&gt;*&lt;/font&gt;&lt;/label&gt;
              &lt;div class="col-lg-9"&gt;
                  &lt;div class="input-group date form_datetime" data-date="dd-M-yyyy"&gt;
                      &lt;input placeholder="Choose Date" class="form-control" value="" onchange="timeValidate()" id="scheduledDate" name="scheduledDate" readonly="readonly" type="text"&gt; &lt;span class="input-group-addon"&gt; &lt;span class="glyphicon glyphicon-th calender-click"&gt;&lt;/span&gt;&lt;/span&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              &lt;label class="col-lg-3 control-label"&gt;Address:&lt;font style="color: red;"&gt;*&lt;/font&gt;&lt;/label&gt;
              &lt;div class="col-lg-9"&gt;
                  &lt;input class="form-control" name="address1" id="address1" placeholder="Full address" value="" type="text"&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
  
  
          &lt;div class="form-group"&gt;
              &lt;label class="col-lg-3 control-label"&gt;City:&lt;/label&gt;
              &lt;div class="col-lg-9"&gt;
                  &lt;input class="form-control" id="" value="Bangalore" name="" placeholder="City Name" readonly="readonly" type="text"&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              &lt;label class="col-lg-3 control-label"&gt;Mobile:&lt;font style="color: red;"&gt;*&lt;/font&gt;&lt;/label&gt;
              &lt;div class="col-lg-9"&gt;
                  &lt;input class="form-control" id="userContactNumber" name="userContactNumber" placeholder="Mobile Number" onkeypress="enableKeys(event);" maxlength="10" type="text"&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
                  &lt;label class="col-lg-3 control-label"&gt;Email:&lt;font style="color: red;"&gt;*&lt;/font&gt;&lt;/label&gt;
                  &lt;div class="col-lg-9"&gt;                                      
                  &lt;input class="form-control" name="addressemailId" id="addressemailId" placeholder="you@example.com" value="" type="text"&gt;                                       
  
                  &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group marg-bot-45"&gt;
              &lt;label class="col-lg-3 control-label"&gt;&lt;/label&gt;
              &lt;div class="col-lg-9"&gt;
                  &lt;a href="index.html" class="btn btn-info"  id="btnBooking"&gt;Confirm Booking&amp;nbsp;&lt;span class="glyphicon glyphicon-ok"&gt;&lt;/span&gt;&lt;/a&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;  
  &lt;/form&gt; 
  </code></pre>
  
  <p><strong>Booking.java</strong></p>
  
  <pre><code>import java.util.Date;
  import java.util.HashSet;
  import java.util.Set;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.FetchType;
  import javax.persistence.GeneratedValue;
  import static javax.persistence.GenerationType.IDENTITY;
  import javax.persistence.Id;
  import javax.persistence.JoinColumn;
  import javax.persistence.ManyToOne;
  import javax.persistence.OneToMany;
  import javax.persistence.Table;
  import javax.persistence.Temporal;
  import javax.persistence.TemporalType;
  
  import org.codehaus.jackson.annotate.JsonIgnoreProperties;
  
  import com.fasterxml.jackson.annotation.JsonIgnore;
  
  /**
   * Booking generated by hbm2java
   */
  @Entity
  @Table(name = "booking", catalog = "service4homes")
  @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
  public class Booking implements java.io.Serializable {
  
      private Integer BId;
      private ServiceProviderStatus serviceProviderStatus;
      private ServiceCategory serviceCategory;
      private Date availDate;
      private String custName;
      private String custMobile;
      private String custEmail;
      private String custAddress;
      private Set&lt;Allocation&gt; allocations = new HashSet&lt;Allocation&gt;(0);
      private Set&lt;SuperAdmin&gt; superAdmins = new HashSet&lt;SuperAdmin&gt;(0);
  
      public Booking() {
      }
  
      public Booking(ServiceProviderStatus serviceProviderStatus,
              Customer customer, ServiceCategory serviceCategory, Date availDate,
              String custEmail) {
          this.serviceProviderStatus = serviceProviderStatus;
          this.serviceCategory = serviceCategory;
          this.availDate = availDate;
          this.custEmail = custEmail;
      }
  
      public Booking(ServiceProviderStatus serviceProviderStatus,
              Customer customer, ServiceCategory serviceCategory, Date availDate,
              String custName, String custMobile, String custEmail,
              String custAddress, Set&lt;Allocation&gt; allocations,
              Set&lt;SuperAdmin&gt; superAdmins) {
          this.serviceProviderStatus = serviceProviderStatus;
          this.serviceCategory = serviceCategory;
          this.availDate = availDate;
          this.custName = custName;
          this.custMobile = custMobile;
          this.custEmail = custEmail;
          this.custAddress = custAddress;
          this.allocations = allocations;
          this.superAdmins = superAdmins;
      }
  
      @Id
      @GeneratedValue(strategy = IDENTITY)
      @Column(name = "b_id", unique = true, nullable = false)
      public Integer getBId() {
          return this.BId;
      }
  
      public void setBId(Integer BId) {
          this.BId = BId;
      }
  
      @ManyToOne(fetch = FetchType.EAGER)
      @JoinColumn(name = "sps_id", nullable = false)
      @JsonIgnore
      public ServiceProviderStatus getServiceProviderStatus() {
          return this.serviceProviderStatus;
      }
  
      public void setServiceProviderStatus(
              ServiceProviderStatus serviceProviderStatus) {
          this.serviceProviderStatus = serviceProviderStatus;
      }
  
      @ManyToOne(fetch = FetchType.EAGER)
      @JoinColumn(name = "sc_id", nullable = false)
      @JsonIgnore
      public ServiceCategory getServiceCategory() {
          return this.serviceCategory;
      }
  
      public void setServiceCategory(ServiceCategory serviceCategory) {
          this.serviceCategory = serviceCategory;
      }
  
      @Temporal(TemporalType.TIMESTAMP)
      @Column(name = "avail_date", nullable = false, length = 19)
      public Date getAvailDate() {
          return this.availDate;
      }
  
      public void setAvailDate(Date availDate) {
          this.availDate = availDate;
      }
  
      @Column(name = "cust_name", length = 50)
      public String getCustName() {
          return this.custName;
      }
  
      public void setCustName(String custName) {
          this.custName = custName;
      }
  
      @Column(name = "cust_mobile", length = 13)
      public String getCustMobile() {
          return this.custMobile;
      }
  
      public void setCustMobile(String custMobile) {
          this.custMobile = custMobile;
      }
  
      @Column(name = "cust_email", nullable = false, length = 50)
      public String getCustEmail() {
          return this.custEmail;
      }
  
      public void setCustEmail(String custEmail) {
          this.custEmail = custEmail;
      }
  
      @Column(name = "cust_address", length = 100)
      public String getCustAddress() {
          return this.custAddress;
      }
  
      public void setCustAddress(String custAddress) {
          this.custAddress = custAddress;
      }
  
      @OneToMany(fetch = FetchType.EAGER, mappedBy = "booking")
      public Set&lt;Allocation&gt; getAllocations() {
          return this.allocations;
      }
  
      public void setAllocations(Set&lt;Allocation&gt; allocations) {
          this.allocations = allocations;
      }
  
      @OneToMany(fetch = FetchType.EAGER, mappedBy = "booking")
      @JsonIgnore
      public Set&lt;SuperAdmin&gt; getSuperAdmins() {
          return this.superAdmins;
      }
  
      public void setSuperAdmins(Set&lt;SuperAdmin&gt; superAdmins) {
          this.superAdmins = superAdmins;
      }
  
  }
  </code></pre>