title: Dynamics CRM 2011 REST API using jQuery
body: <p>I personally don't have any  experience with CRM 2011 and only recently found out about the REST oData API so decided to have a crack at it using basic jQuery ajax calls. I created a basic html page and put the following code in there from snippets that I picked up from various Google searches. Seems like a fairly straightforward call:</p>
  
  <pre><code>var serverurl = 'http://[OrganizationUrl]/XRMServices/2011/OrganizationData.svc/[PrivateEntity]?$select=[PrivateEntity_Field1],[PrivateEntity_Field2]';
  
  $.ajax({
      beforeSend: function (xhr) {
          xhr.setRequestHeader('Accept', 'application/json');
      },
      url: serverurl,
      type: 'GET',
      dataType: 'jsonp',
      contentType: 'application/json; charset=utf-8',
      success: function (data) {
          alert('success');
      },
      error: function (xhr, status, error) {
          alert("Error : " + status);
      },
  }); 
  </code></pre>
  
  <p>All this does is go to the error callback and alert "Error: parseerror".</p>
  
  <p>A closer inspection on FireBug yields the following request and response headers:<img src="https://i.stack.imgur.com/BtakF.png" alt="Firebug Output"></p>
  
  <p>Despite explicitly specifying json in the header and content it still brings back xml/atom feed and still goes the the error callback instead of the success.</p>
  
  <p>Does this JavaScript have to be executed from within CRM i.e. deployed to CRM first? Or can it work as I've done from an external self contained HTML page? I'm familiar with jQuery but not familiar with CRM or this REST API so a little out of my depth here. Any help is appreciated</p>
  
  <p><strong>UPDATE</strong>: I've executed the following code in fiddler and it brings back what I expect from CRM:</p>
  
  <pre><code>GET http://[OrganizationUrl]/XRMServices/2011/OrganizationData.svc/[PrivateEntity]?$select=[PrivateEntity_Field1],[PrivateEntity_Field2] HTTP/1.1
  User-Agent: Fiddler
  Host: melmd0105:5555
  Accept:  application/json
  </code></pre>