title: Ajax Jquery Request with WEB API
body: <p>I'm trying to retrieve a JSON result from a WEB API call.</p>
  
  <p>My WEP API method:</p>
  
  <pre><code>[AcceptVerbs("GET", "POST")]
      public object GetTest()
      {
           rep = new ChatRepository();
          chatBoxCLS box = rep.Chatrequest(chatRequestLevel.Parent, null);
  
          System.Web.Mvc.JsonResult jsonResult = new System.Web.Mvc.JsonResult
          {
              Data = box,
              JsonRequestBehavior = System.Web.Mvc.JsonRequestBehavior.AllowGet
          };
  
  
          return jsonResult.Data;
      }
  </code></pre>
  
  <p>I have modified the WebapiConfig.cs as below, so that it will always return JSON</p>
  
  <pre><code> config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: new { action = "get", id = RouteParameter.Optional }
            );
  
              var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t =&gt; t.MediaType == "application/xml");
              config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);
  </code></pre>
  
  <p>Below is my Jquery ajax call:</p>
  
  <pre><code>&lt;script type='text/javascript'&gt;
  
      $(document).ready(function () {
  
          $.ajax({
              type: 'GET',
              url: 'http://localhost:6606/api/values/GetTest',
  
              dataType: 'json',
  
              crossDomain: true,
              success: function (msg) {
  
                  alert('success');
  
              },
              error: function (request, status, error) {
  
                  alert('error');
              }
          });
      });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>It's always end up in error alert. no data is received from the WEB API. I tried debugging and found that my request successfully hits the WEB API method and return JSON. Below is the JSON data it returns.</p>
  
  <blockquote>
    <p>{"listOfItems":[{"id":14,"description":"New
    test","display_number":1},{"id":4,"description":"operational","display_number":2},{"id":3,"description":"sales","display_number":3},{"id":5,"description":"technical","display_number":4}],"reply":null,"history":null,"Initialhistory":null,"Question":"","chatids":null,"displayNum":null}</p>
  </blockquote>
  
  <p>why am i not getting any result on client side?</p>