//////////////////////////// Call Token Authontication
function CallAPI_Authoticate(objvr) {
var objvr = {
grant_type:
'password',
username:
$("[id$=UserName]").val(),
password:
$("[id$=Password]").val(),
scope: $('[id$=AnyOtherParameter]').val()
};
$.ajax({
type: "POST",
url: "BsaeURL/"+"Token",
headers: { "Accept": "application/json" },
contentType: "application/x-www-form-url; charset=urf-8",
data: objvr,
async: false,
success: function (result) {
if (result != "Error")
CallAPI_Authorized(result);
},
error: function (req, status, error) {
Show_Alert_Msg(JSON.parse(req.responseText).error_description);
}
});
}
//////////////////////////// After Authontication API data comming in JSON
function CallAPI_Authorized(token)
{
var tokes =
token.access_token;
var Baseulr= "http://localhost:60005"
var APIURL= "/api/data/GetEmployees";
$.ajax({
type: "GET",
url: "BaseUrl" + "APIURL",
async: false,
headers: {
Authorization: 'Bearer ' + tokes
},
dataType: 'json',
success: function (result, status, xhr) {
Other working code here....
},
error: function (req, status, error) {
Show_Alert_Msg(JSON.parse(req.responseText).error_description);
}
});
}
////////////////////////////
[{"districtName":"Haveri","districtCode":"11","talukName":"Haveri","talukCode":"1104","hobliName":"HAVERI","hobliCode":"110401","villageName":"Gowrapura.M.Adura","villageCode":"1104010013","message":"Data Available"}]