Reputation: 1508
I am making a Web API 2 project and I have the following code. I am making a Web API call to get a list of items and then I will display them. The following code works but now security has been added and I need to add a "AuthToken" to the header of the request.
$(document).ready(function () {
// Send an AJAX request
$.getJSON(uri)
.done(function (data) {
// On success, 'data' contains a list of products.
$.each(data, function (key, item) {
// Add a list item for the product.
$('<li>', { text: formatItem(item) }).appendTo($('#products'));
});
});
});
How can I modify my code to include the AuthToken in the header?
Upvotes: 0
Views: 83
Reputation: 2885
So the issue here is $.getJSON()
.
$.getJSON()
is shorthand for $.ajax()
and doesn't allow you to add headers. You will need to use $.ajax()
.
See this answer: Can you add headers to getJSON in jQuery?
Upvotes: 3