Github Gist: New Lines?
Github Gist: New Lines?
我正在尝试创建一个包含多行内容的要点,但不确定最佳方法。 ' 不起作用,添加两个空行也不起作用。它显示为一行文本。
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);
});
如何更改内容变量以包含换行符?我希望输出最终显示为.txt,所以我认为我不能更改媒体类型?谢谢。
这只是
一个猜测,但可能是因为您手动进行了 JSON 化,并且'n
未正确转义。尝试使用JSON.stringify
:
JSON.stringify({"description": "a gist for a user with token api call via ajax","public": true,"files": {"file1.txt": {"content": content }}})
相关文章:
- 使用:new Image()控制加载html.src=html_URL
- 如何在不使用 new 关键字的情况下从函数创建对象
- 为什么要做新的.Date()与new相差1小时.日期().到ISOString()
- “createImageData()”和“new ImageData(()”有何不同
- 返回值+new Date()与Date.now()是否不同
- 删除LINES开头和结尾的空白
- new SharedWorker(“whatever.js”)返回一个错误
- Animation cuts off multiple lines of text in <p>
- new Datamap() 在调用之间保持内存的共享状态
- new XMLHttpRequest().responseType empty
- a=1和a=new Number()之间的差异
- JavaScript“new Date()”使用哪个时区
- JS new.target vs. instanceof
- 为什么(new RegExp(“w”)==/w/)在JS中为false
- JavaScript-使用B.prototype=new A()继承数组
- 为什么使用“new”创建一个Javascript数组被认为是不好的
- “new”关键字是在构造对象时自动设置“constructor”属性的唯一方法吗
- typeof new Function()总是“;函数”;
- new Date('2011-12-15 00:00:00') is showing up as NaN
- Github Gist: New Lines?