title: Resteasy Ajax POST call
body: <p>I cant get my Ajax post to work with Resteasy. I get no error in java, but in browser i get this : </p>
  
  <pre><code>event.returnValue is deprecated. Please use the standard event.preventDefault() instead. 
  OPTIONS https://localhost:8081/TestResteasy/rest/servlet/post  
  </code></pre>
  
  <p>Can anyone tell me what i did wrong?
  If i type the link directly,the service works just fine.</p>
  
  <p>js file</p>
  
  <pre><code>$(document).ready(function() {
  $("button").click(function() {
      var dataT = {
          "name" : "Daniel",
          "password" : "1234"
      };
  
      $.ajax({
          type : "POST",
          data : JSON.stringify(dataT),
          dataType : "json",
          contentType : "application/json",
          url : "https://localhost:8081/TestResteasy/rest/servlet/post",
          success : function(data) {
              alert(data);
          }
      });
  });
  </code></pre>
  
  <p>});</p>
  
  <p>web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://java.sun.com/xml/ns/javaee"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  id="WebApp_ID" version="3.0"&gt;
  &lt;display-name&gt;JAXRS-RESTEasy&lt;/display-name&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;resteasy-servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  &lt;!-- Auto scan REST service --&gt;
  &lt;context-param&gt;
      &lt;param-name&gt;resteasy.scan&lt;/param-name&gt;
      &lt;param-value&gt;true&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;!-- this should be the same URL pattern as the servlet-mapping property --&gt;
  &lt;context-param&gt;
      &lt;param-name&gt;resteasy.servlet.mapping.prefix&lt;/param-name&gt;
      &lt;param-value&gt;/rest&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;listener&gt;
      &lt;listener-class&gt;
          org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
          &lt;/listener-class&gt;
  &lt;/listener&gt;
  
  &lt;servlet&gt;
      &lt;servlet-name&gt;resteasy-servlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;
          org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
      &lt;/servlet-class&gt;
  &lt;/servlet&gt;
  </code></pre>
  
  <p></p>
  
  <p>the service</p>
  
  <pre><code>@Path("/servlet")
  public class RESTEasyHelloWorldService {
  
  @GET
  @Path("/get/{pathParameter}")
  public Response responseMsg(
          @PathParam("pathParameter") String pathParameter,
          @DefaultValue("Nothing to say") @QueryParam("queryParameter") String queryParameter) {
  
      String response = "Hello from: " + pathParameter + " : "
              + queryParameter;
  
      return Response.status(200).entity(response).build();
  }
  
  @POST
  @Path("/post")
  @Consumes("application/json")
  public Response createProductInJSON(Product product) {
  
      String result = "Product created : " + product.getName();
      System.out.println(product.getName());
      return Response.status(201).entity(result).build();
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>the object</p>
  
  <pre><code>package com.javacodegeeks.enterprise.rest.domain;
  
  public class Product {
  
  String name;
  String password;
  
  public Product(String name, String password) {
      this.name = name;
      this.password = password;
  }
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
  public String getPassword() {
      return password;
  }
  
  public void setPassword(String password) {
      this.password = password;
  }
  
  @Override
  public String toString() {
      return "Product [name=" + name + ", qty=" + password + "]";
  }
  </code></pre>
  
  <p>}</p>
  
  <p>pom.xml</p>
  
  <pre><code>    &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
          &lt;artifactId&gt;resteasy-jaxrs&lt;/artifactId&gt;
          &lt;version&gt;3.0.4.Final&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
          &lt;artifactId&gt;resteasy-jackson-provider&lt;/artifactId&gt;
          &lt;version&gt;3.0.2.Final&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>