I am trying to hit API in javascript but getting error code 401 but on postman it is working fine.
Here is my javascript code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ABC</title>
<script src="jquery-3.1.0.min.js"></script>
</head>
<body onload="test()"> </body>
<script type="text/javascript">
function test()
{
var credential = '[{"id":"recording", "userId":"administrator", "password":"Expert111"}]'
$.ajax({
url: "http://xx.xx.xx.xx/api/rest/authorize",
type: "POST",
data: { id: "recording", userId: "administrator", password: "Expert111" },
dataType: "jsonp",
success: function (result) {
switch (result) {
case true:
alert("Success");
break;
default:
alert("fail:"+result);
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert("status: " +xhr.status +", ajaxOptions:"+ajaxOptions +",Error:" +thrownError);
},
//data : credential
});
};
</script>
</html>
following is postman snapshot (working fine)
following is result of request via code: