0

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?

1 Answer 1

3

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.