Github Gist: New Lines?

I am trying to create a gist with multiple lines of content, but not sure if this is the best way. \ n doesn't work and doesn't add two blank lines. It displays as a single line of text.

var content = 'content on\nnewline here';
$.ajax({ 
    url: 'https://api.github.com/gists',
    type: 'POST',
    beforeSend: function(xhr) { 
        xhr.setRequestHeader("Authorization", "token TOKEN-HERE"); 
    },
    data: '{"description": "a gist for a user with token api call via ajax","public": true,"files": {"file1.txt": {"content": "' + content + '"}}}'
}).done(function(response) {
    console.log(response.id);
});

      

How do I change the content variable to contain newlines? I want the output to end up being rendered as .txt, so I don't think I can change the media type? Thank.

+3


source to share


1 answer


This is just a guess, but it might be because you are JSON-ifying by hand and \n

not being executed properly. Try using JSON.stringify

:



JSON.stringify({"description": "a gist for a user with token api call via ajax","public": true,"files": {"file1.txt": {"content": content }}})

      

+3


source







All Articles