I'm having trouble accessing api using the $.ajax({})
function of jQuery.
The Error:
Mycode:
<!DOCTYPEhtml><html><head><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
function auth() {
var credentials = {
apikey: "my_apiKey",
username: "myuser",
userkey: "my_userKey"
};
$.ajax({
type: "POST",
contentType: "application/json",
url: "https://api.thetvdb.com/login",
data: credentials,
dataType: "json",
success: function(data) {
console.log(data);
}
});
}
auth();
</script>
</head>
<body>
</body>
</html>
I tested using the program Advanced REST client
, and it worked perfectly, it returned me token
.
I'm using the chrome browser, but I tested it on edge / ie and gave the same error.
Does anyone know how I can do this?