title: Jquery ajax call getting 'error' with swagger rest api
body: <p>I used a swagger script to generate a rest api.</p>
  
  <pre><code>{
    "swagger": "2.0",
    ...
  },
  "host": "localhost:8080",
  "basePath": "/swagger-item-jaxrs",
  "schemes": [ "http" ],
  "consumes": [ "application/json" ],
  "produces": [ "application/json" ],
  "paths": {
  "/item/{cd}": {
    "get": {
      "description": "Returns an item based on the item code passed.",
      "operationId": "findItemById",
      "produces": [
        "application/json",
        "application/xml",
        "text/xml",
        "text/html"
      ],
      "parameters": [
        {
          "name": "cd",
          "in": "path",
          "description": "CD of item to fetch",
          "required": true,
          "type": "string"
        }
      ],
      "responses": {
        "200": {
          "description": "item response",
          "schema": {
            "$ref": "#/definitions/item"
          }
        },
        "default": {
          "description": "unexpected error",
          "schema": {
            "$ref": "#/definitions/errorModel"
          }
        }
      }
    }
  }
  },
  "definitions": {
  "item": {
    "type": "object",
    "required": [
      "cd",
      "name"
    ],
    "properties": {
      "cd": {
        "type": "string"
      },
      "name": {
        "type": "string"
      },
      "tag": {
        "type": "string"
      }
    }
  },
  "errorModel": {
    "type": "object",
    "required": [
      "code",
      "message"
    ],
    "properties": {
      "code": {
        "type": "integer",
        "format": "int32"
      },
      "message": {
        "type": "string"
      }
    }
  }
  }
  }
  </code></pre>
  
  <p>I can call the api using the client generate java classes, I can even enter the url into the browser and get a response.</p>
  
  <p>Browser: <a href="http://localhost:8080/swagger-item-jaxrs/item/0446840" rel="nofollow noreferrer">http://localhost:8080/swagger-item-jaxrs/item/0446840</a></p>
  
  <p>Response: <code>{"cd":"0446840","name":"ROYAL BASMATI RICE  "}</code></p>
  
  <p>The Swagger UI can even get the same response back and indicates that the curl command is: <code>curl -X GET "http://localhost:8080/swagger-item-jaxrs/item/0446840" -H  "accept: application/json"</code></p>
  
  <p>My ajax code:</p>
  
  <p><code>$.ajax({
        url: "http://localhost:8080/swagger-item-jaxrs/item/0446840"
        , method: "GET"
        , headers: { "accept": "application/json" }
       })
      .done(function(data) {
        alert('success');
        console.log('success: ');
        console.log(data);
      })
      .fail(function(err) {
        console.log('error: ');
        console.log(err);
      });</code></p>
  
  <p>Chrome developer tools console results:</p>
  
  <p><code>error:
  Object {readyState: 0, getResponseHeader: function, getAllResponseHeaders: function, setRequestHeader: function, overrideMimeType: function…}</code></p>
  
  <p>Any help would be greatly appreciated.</p>