We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

401 Unauthorized when calling when doing AJAX call from SPFX webpart, Working perfectly from postman

KavithaSP
Tera Contributor

I want to create an incident in Service now using SharePoint SPFX JavaScript mode,

Here is the token generation code. It's working fine from postman but not from SharePoint spfx 

I'm getting.   net::ERR_ABORTED 401 (Unauthorized) 

 

$.ajax({
url: "https://company.com/oauth_token.do",
type: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT"
},
crossDomain: true,
dataType : 'jsonp',
data: {
"grant_type": "password",
"client_id": "123123213",
"client_secret": "123213213",
"username": "test_user",
"password": "12345132"
},
success: function() {

alert("success");
},
error: function() {
alert("error");
}
});

 

0 REPLIES 0