我想在以下请求中添加标题,但不确定如何添加它? “接受”:“application / json; odata = verbose”;
感谢任何帮助!
function getArticleList() {
var ajax = new XMLHttpRequest();
ajax.open("GET", "/content/_api/web/lists/getbytitle('topsupportarticles')/items?", true);
ajax.onload = function () {
var list = JSON.parse(ajax.responseText).map(function (i) { return i.Title + "<p id='dt'>-" + i.KBID + "</p>"; });
console.log(i.Title + " " + i.KBID);
//new Awesomplete(document.querySelector("#Title_fa564e0f-0c70-4ab9-b863-0177e6ddd247_$TextField"), { list: list });
// $(".input-loader").css("background-image", "none");
};
ajax.send();
}
答案 0 :(得分:2)
以下是 XMLHttpRequest 文档的链接 https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/setRequestHeader
这就是你要找的东西吗?
答案 1 :(得分:2)
您可以使用它:
ajax.setRequestHeader("Accept","application/json");