5

JavaScript を使用してパブリック Gist を作成しようとしています。私は認証を使用していません - これはすべてクライアント側です。

var gist = {
    "description": "test",
    "public": true,
    "files": {
        "test.txt": {
            "content": "contents"
        }
    }
};

$.post('https://api.github.com/gists', gist, function(data) {
});

上記のコードは 400: Bad Request - Problems parseing JSON をスローします。ただし、私の JSON は有効です。何か案は?

4

1 に答える 1

10

あはは - $.post にオブジェクトを渡すことができません。最初に文字列化する必要があります。

var gist = {
    "description": "test",
    "public": true,
    "files": {
        "test.txt": {
            "content": "contents"
        }
    }
};

$.post('https://api.github.com/gists', JSON.stringify(gist), function(data) {});
于 2012-03-23T15:26:02.267 に答える