1
Good morning,
In my work, a biometric reader system was implemented to control the output and entry of personnel. Such a system has an API, which gives access to your data. Every API is in Ajax with Jquery. I looked at W3schools on the site https://www.w3schools.com/jquery/ajax_ajax.asp and learned how to do it. This is the API code:
$.ajax({
url: "/login.fcgi",
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({
login: 'admin',
password: 'admin'
}),
success: function(data) {
session = data.session;
}
});
So I made the following HTML:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.ajax({
url: "http://10.3.48.199/login.fcgi",
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({
login: 'admin',
password: 'admin'
}),
success: function(data) {
session = data.session;
}
});
});
});
</script>
</head>
<body>
<button>Teste</button>
</body>
</html>
However, when I click the button, it, on the console, gives me errors of CORS
. I searched the internet and added the following line below the url line: "Access-Control-Allow-Origin: *,"
. This removed the error of CORS
. But, I cannot access the server. No error appears. No message appears either. I have tried to give a message alert
to see if the session would appear, but also nothing. Can anyone help me? Maybe it’s a code semantic error.
What returns in variable
data
, insidesuccess
? Put aconsole.log(data)
and see what returns in the browser console.– Douglas Garrido
The API does not have its own authentication system or is already used?
– Woss
use Chrome dev tools and look at the "network" tab to see how the request is behaving.
– v42
Try removing the contenttype.
– Aline
I used the.log(data) console and nothing appears in the Firefox browser and nothing appears.
– Luiz da Mata
The API has its own authentication system, but I’m accessing the manufacturer’s API manual to create our own personal input and output control system, taking only the database from the biometric reader.
– Luiz da Mata
I removed the content type but saw no difference.
– Luiz da Mata
Unfortunately here in the company is not allowed to use Chrome :(
– Luiz da Mata
I’m wondering if this <pre>Access-Control-Allow-Origin: *,</pre> is right.
– Luiz da Mata
If I access the link http://10.3.48.199/login.fcgi, it generates me the following in the browser:
{"error":"Invalid data","code":1}
– Luiz da Mata
I tested the
console.log(...)
in firefox and did not work.– Iago Frota
@Luizdamata, put your contacts in the profile of Stackoverflow. I wanted to talk to you.
– Iago Frota