title: jQuery Ajax/Jetty; Chrome javascript console showing 'Uncaught SyntaxError: Unexpected identifier' from server response
body: <p>I'm trying to make a jQuery mobile app read data from a server I'm running on another computer. When I load the page, I get my 'There was an error loading the data.' message rather than 'Hello World' in my <p> element. And in the JavaScript console in Chrome, I'm being told that there's 'Uncaught SyntaxError: Unexpected identifier' in my server's 'Hello World' response. </p>
  
  <p>I'm stuck, any suggestions? Code for my js and for my Jetty server pasted below:</p>
  
  <p>Here's my Javscript/jQuery:</p>
  
  <pre><code>&lt;script&gt;
  
  $.ajax({
      url: 'redacted-my computer's ip',
      dataType: 'jsonp',
  
      timeout: 5000,
      success: function(data, status){
          $("p").html(data);
          }
      ,
      error: function(){
          $("p").html('There was an error loading the data.');
      }
  });
  
  
  &lt;/script&gt;
  </code></pre>
  
  <p>And here's my Java code:</p>
  
  <pre><code>public class HelloServlet extends HttpServlet{
  private String greeting="Hello World";
  public HelloServlet(){}
  public HelloServlet(String greeting)
  {
      this.greeting=greeting;
  }
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
  {
      response.setContentType("text/plain");
      response.setStatus(HttpServletResponse.SC_OK);
      response.getWriter().println(greeting);
  
  }
  /**
   * @param args the command line arguments
   */
  public static void main(String[] args) {
      // TODO code application logic here
      Server server = new Server(8082);
      HelloServlet helloServ = new HelloServlet();
  
      ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
      context.setContextPath("/");
      server.setHandler(context);
  
      context.addServlet(new ServletHolder(helloServ), "/*");
  
  
      try {
          server.start();
      } catch (Exception ex) {
          Logger.getLogger(HelloServlet.class.getName()).log(Level.SEVERE, null, ex);
      }
      try {
          server.join();
      } catch (InterruptedException ex) {
          Logger.getLogger(HelloServlet.class.getName()).log(Level.SEVERE, null, ex);
      }
  }
  </code></pre>