Tim
Tim

Reputation: 593

How to add header to this ajax request

I would like to add a header to the following request but unsure how to add it?

"Accept":"application/json; odata=verbose";

Here is my code:

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();
    }

Upvotes: 0

Views: 94

Answers (2)

Amarjeet Kaur
Amarjeet Kaur

Reputation: 157

You may use it like:

ajax.setRequestHeader("Accept","application/json");

Upvotes: 2

arseniyandru
arseniyandru

Reputation: 798

Here is link to documentation for XMLHttpRequest https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/setRequestHeader

Is that what you are looking for?

Upvotes: 2

Related Questions