Ajax request with JQuery

1

Good morning,

In my work, a biometric reader system was implemented to control the exit and entry of personnel. Such a system has an API that gives access to your data. Every API is in Ajax with JQuery. I looked at W3Schools on link and learned how to do that. 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 did 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 CORS error. But, I can not access the server. No error appears. Also no message appears. I already tried to give alert to see if the session appeared, but also nothing. Can someone help me? Maybe it's code semantics error.

    
asked by anonymous 08.03.2017 / 14:52

0 answers