title: Posting data to Jax-RS using ajax
body: <p>I am a new to Jax-RS and I am having some problems consuming my web service from ajax. My get requests are working as should be, and now I am trying to post some data to be saved to Oracle 11g database, my ajax call is returning just error which is making it hard to debug. </p>
  
  <p>here is my ajax call</p>
  
  <pre><code> function save(img)   // base64 encoded string
  {
  
  
  $.ajax({
      type: "POST",
      url: "http://192.168.42.179:8082/PotholeWebservice/webresources/entities.pothole/post",
      data: img,
      dataType: "json",
      success: function(data)
      {
          alert("saved to database");
      },
      error: function(textStatus, errorThrown)
      {
          alert("error in saving to database: " + textStatus + " " + errorThrown);
      }
  });
  }
  </code></pre>
  
  <p>here is my jax-rs post method</p>
  
  <pre><code> @POST
  @Path("post")
  @Consumes({"application/xml", "application/json"})
  public void create(@PathParam("paramImg") String paramImg) {
  
      Date date = new Date();
      BASE64Decoder decoder = new BASE64Decoder(); // decode base64 image to byte[]
      byte[] decodedBytes = null;
      try {
          decodedBytes = decoder.decodeBuffer(paramImg);
      } catch (IOException ex) {
          Logger.getLogger(PotholeFacadeREST.class.getName()).log(Level.SEVERE, null, ex);
      }
  
      Pothole entity = new Pothole(decodedBytes, date);
      super.create(entity);
  
  }
  </code></pre>
  
  <p>super class</p>
  
  <pre><code>// super.create
  public void create(T entity) {
      getEntityManager().persist(entity);
  
  }
  </code></pre>
  
  <p>my class</p>
  
  <pre><code>public class Pothole implements Serializable {
  private static final long serialVersionUID = 1L;
  @Basic(optional = false)
  @NotNull
  @Lob
  @Column(name = "IMAGE")
  private byte[] image;
  // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
  
  @Id 
  @GeneratedValue(generator = "ID_Seq")
  @SequenceGenerator(name="IDSeq",sequenceName="ID_SEQ", allocationSize=1) 
  @Basic(optional = false)
  @NotNull
  @Column(name = "ID")
  private BigDecimal id;
  
  @Basic(optional = false)
  @NotNull
  @Column(name = "PDATE")
  @Temporal(TemporalType.TIMESTAMP)
  private Date pdate;
  
  public Pothole() {
  }
  
  public Pothole(BigDecimal id) {
      this.id = id;
  }
  
  public Pothole( byte[] image, Date pdate) {
  
      this.image = image;
      this.pdate = pdate;
  }
  
  public byte[] getImage() {
      return image;
  }
  
  public void setImage(byte[] image) {
      this.image = image;
  }
  
  public BigDecimal getId() {
      return id;
  }
  
  public void setId(BigDecimal id) {
      this.id = id;
  }
  
  public Date getPdate() {
      return pdate;
  }
  
  public void setPdate(Date pdate) {
      this.pdate = pdate;
  }
  </code></pre>