title: jQuery GET fails with no error message
body: <p>I'm making a <code>GET</code> request against a WCF web service. My WCF service is located at <code>http://localhost/RestService/RestService.svc/web/GetMessage</code> and has the following interface:</p>
  
  <pre><code>[OperationContract]
  [WebGet(UriTemplate = "GetMessage", ResponseFormat = WebMessageFormat.Json)]
  String GetMessage();
  </code></pre>
  
  <p>The endpoint is configured properly as I can make a bare call within my browser:</p>
  
  <pre><code>  &lt;system.serviceModel&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="WebServiceBehavior"&gt;
            &lt;serviceMetadata httpGetEnabled="true" /&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
  
        &lt;endpointBehaviors&gt;
          &lt;behavior name="WebEndpointBehavior"&gt;
            &lt;webHttp /&gt;
            &lt;/behavior&gt;
        &lt;/endpointBehaviors&gt;
      &lt;/behaviors&gt;
  
      &lt;services&gt;
        &lt;service name="TestRestService.RestService"
                 behaviorConfiguration="WebServiceBehavior"&gt;
          &lt;endpoint name="RestWeb"
                    address="web"
                    binding="webHttpBinding"
                    behaviorConfiguration="WebEndpointBehavior"
                    contract="TestRestService.IRestService" /&gt;
        &lt;/service&gt;
      &lt;/services&gt;
    &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>Calling it via navigation in my browser returns:</p>
  
  <pre><code>{"GetMessageResult":"Hello World!"}
  </code></pre>
  
  <p>So far so good. No problems here. A quick look at the <a href="http://api.jquery.com/jQuery.get/" rel="nofollow noreferrer">jQuery documentation</a> for performing a <code>GET</code> yields:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;script type="text/javascript" src="jquery-1.7.2.min.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript"&gt;
              $.ajax({
                  url: 'http://localhost/RestService/RestService.svc/web/GetMessage',
                  type: 'GET',
                  dataType: 'json',
                  success: function (data) {
                      alert(data);
                  },
                  error: function (xhr, status, message) {
                      alert("Error: " + status + " " + message); }
                  });
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I run this in a small html test page using jQuery 1.72 and I get the following error:</p>
  
  <pre><code>Error: error
  </code></pre>
  
  <p>What gives? The error message handler <a href="https://stackoverflow.com/questions/4062317/jquery-get-error-response-function">that I found here</a> gives me <em>absolutely zero</em> useful information. Simply put:</p>
  
  <ul>
  <li>Why is my GET failing?</li>
  <li>Why is the error message useless?</li>
  </ul>
  
  <h1>Solution</h1>
  
  <p>As it turns out, jQuery does not natively support cross-domain ajax requests as Kevin B <a href="https://stackoverflow.com/a/11265761/312124">suggested in his answer</a>. To fix this I had to switch to using <code>dataType: 'jsonp'</code> and add a <code>webHttpBinding</code> with the <code>crossDomainScriptEnabled</code> property enabled:</p>
  
  <pre><code>&lt;bindings&gt;
    &lt;webHttpBinding&gt;
      &lt;binding name="WebBindingWithScripts"
               crossDomainScriptAccessEnabled="true"&gt;
        &lt;security mode="None" /&gt;
      &lt;/binding&gt;
    &lt;/webHttpBinding&gt;
  &lt;/bindings&gt;
  
  
  &lt;endpoint name="RestWeb"
            address="web"
            binding="webHttpBinding"
            behaviorConfiguration="WebEndpointBEhavior"
            bindingConfiguration="WebBindingWithScripts"
            contract="TestService.IRestService"&gt;
  &lt;/endpoint&gt;
  </code></pre>
  
  <p>When using only <code>dataType: 'jsonp'</code>, you will still get errors unless you configure your WCF service to allow cross domain scripts.</p>