title: Access Jersey based RESTful service using jQuery
body: <p>I am trying to access RESTful service, created on Java and deployed with help of Jersey using jQuery.</p>
  
  <p>If I access it using browser I will get the result, but from jQuery, I am getting an error and can not see any results on the page.</p>
  
  <p>Page with the script is hosting on local Apache server and the Service is running separately using Jersey/Grizzly on the same machine. </p>
  
  <p>I can see that service is sending the response and it has 200 code, but I keep getting error from .ajax, without any details and
  Any suggestions what is wrong?</p>
  
  <p>Service:</p>
  
  <pre><code>@Path("/helloworld")
  </code></pre>
  
  <p>public class HelloWorldResource {</p>
  
  <pre><code>@GET
  @Produces
  public String test(){
      System.out.println("Sending response");
      return "test";
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Main:</p>
  
  <pre><code> public static void main(String[] args) throws IOException {
  
      final String baseUri = "http://localhost:9998/";
      final Map&lt;String, String&gt; initParams = new HashMap&lt;String, String&gt;();
      initParams.put("com.sun.jersey.config.property.packages",
              "resources");
      System.out.println("Starting grizly");
      SelectorThread threadSelector = GrizzlyWebContainerFactory.create(baseUri, initParams);
  
      System.out.println(String.format(
              "Jersey app started with WADL available at %sapplication.wadl\n"
              + "Try out %shelloworld\nHit enter to stop it...", baseUri, baseUri));
      System.in.read();
      threadSelector.stopEndpoint();
      System.exit(0);
  
  }
  </code></pre>
  
  <p>JavaScript:</p>
  
  <pre><code>var serviceAddress = "http://192.168.1.2:9998/helloworld";
          function loadDeviceData(){
              $.ajax({
                  DataType: "text",
                  url: serviceAddress,
                  success: function (data) {
                      alert("Data loaded: " + data);
                  },
                  error: function (xhr) {
                      alert(xhr.responseText + ' ' + xhr.status + ' ' + xhr.statusText);
                  }
              });
          }
  </code></pre>