Search code examples
jquerygithubgithub-apigist

save anonymous github gist with jQuery.ajax()


I'm having trouble using jQuery.ajax() to post a gist to Github. The gist is created, and the response is 201 Created, but the response tab in Firebug is empty and the error callback is hit.

  var data = {
    "description": "posting gist test",
    "public": true,
    "files": {
      "test.txt": {
        "content": "hello gist!"
      }
    }
  }
  $.ajax({
    url: 'https://api.github.com/gists',
    type: 'POST',
    dataType: 'json',
    data: JSON.stringify(data)
  })
  .success( function(e) {
    console.log(e);
  })
  .error( function(e) {
    console.warn("gist save error", e);
  });

Frustratingly, it works fine in jsfiddle: http://jsfiddle.net/vXpCV/


Maybe this is the issue. jsFiddle is getting different response headers:

Access-Control-Allow-Cred...    true
Access-Control-Allow-Orig...    http://fiddle.jshell.net
Access-Control-Expose-Hea...    Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-OAuth-Scopes, X-Accepted-OAuth-Scopes
Connection  keep-alive
Content-Length  1093
Content-Type    application/json; charset=utf-8
...

Solution

  • Adding my http://local.dev/ to https://github.com/settings/applications seemed to fix it.