locked
Pass auth token to web api from jquery RRS feed

  • Question

  • User-257070954 posted

    Hi all,

              I am trying to call one web api from jquery . But i am getting console error like below. How i overcome this?

               Failed to load resource: the server responded with a status of 401 ()

            But when i try by using postman i can access this. So where is the issue? below i giving my code

        

    var url = "https://api.thinghub.io/v0/user";
    $.ajax({


    url: url + "/" + user,
    dataType: "jsonp",
    headers: { "Content-Type": "application/json", "Authorization": uuid },
    type: 'GET',
    contentType: "application/json",
    beforeSend: function setHeader(xhr) {
    xhr.setRequestHeader('X-VN-ad', "sdd");
    xhr.setRequestHeader('X-VN-APs', "mei");
    },
    success: function (data) {
    },

    error: function (xhr, ajaxOptions, thrownError) {

    alert("error occoured")

    }

    });

    });

           I believe issue related to header only. Please let me know how can we pass header value to api from jaquery?

     

    Tuesday, June 19, 2018 12:36 PM

Answers

All replies