title: Unable to call simple REST web service from ajax
body: <p>I am developing an web application using rest web services. I am trying to call the simple web service from the ajax. But I am not getting desired output.
  My web service code is:</p>
  
  <pre><code>@Path("hello")
  public class Hello {
  
     @GET
     @Path("/first")
     @Produces("text/html")
     public String function1(){
     return "Something happens";
     }
  }
  </code></pre>
  
  <p>and my html file which gives ajax call for rest web service is:</p>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;JSP Page&lt;/title&gt;
          &lt;script&gt;
              function callme(){
              alert("hello");
  
          $.ajax({
              type: "GET",
              url: "http://localhost:8080/WebApplication4/webresources/hello/first",
              data:"",
              dataType:"text",
              contentType: "text/html",
               success: function(resp){alert("Server says" + resp);},
               error: function(e){ alert("An error has occured");},
  
           });
         }
        &lt;/script&gt; 
      &lt;/head&gt;
  
      &lt;body&gt;
  
          &lt;form id="form1" method="GET" onsubmit="callme();"&gt;
              &lt;input type="text" name="t1"&gt;
              &lt;input type="submit" Value="SUBMIT"&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>When I call web service from the browser, then my web service gives return value as expected.
  I call web service from browser as <code>http://localhost:8080/WebApplication4/webresources/hello/first</code>
  and it return with text <code>"Something happens"</code>
  What goes wrong here with ajax call?
   And also How can capture the returned json object in ajax?
  Thank you</p>