I guess that you are not using same web session, so Traccar session is not saved across requests.
Hi Anton,
I am using this code.
What am I doing wrong?
Getting 404 at line
$.get("http://demo.traccar.org/api/session")
<html>
<head>
<script type="text/javascript" src="jquery-3.1.0.min.js" charset="UTF-8"></script>
</head>
<body>
<script type="text/javascript">
$.post("http://demo.traccar.org/api/session", {email:"***", password:"***"})
.done(function(data){
$("body").append((JSON.stringify(data)));
$("body").append("<br/>");
$.get("http://demo.traccar.org/api/session").done(function(data){
$("body").append((JSON.stringify(data)));
});
}
);
</script>
</body>
</html>
Because it's a cross-domain request, I think you need to use "withCredentials" parameter to keep sessions cookie.
Anton, thank you.
It was a cross-domain problem.
This is the code that works:
<html>
<head>
<script type="text/javascript" src="jquery-3.1.0.min.js" charset="UTF-8"></script>
</head>
<body>
<script type="text/javascript">
$.ajaxSetup({
crossDomain: true,
xhrFields: {
withCredentials: true
}
});
$.post("http://demo.traccar.org/api/session", {email:"***", password:"***"})
.done(function(data){
$("body").append((JSON.stringify(data)));
$("body").append("<br/>");
$.get("http://demo.traccar.org/api/session").done(function(data){
$("body").append((JSON.stringify(data)));
window.location.replace("http://demo.traccar.org");
});
});
</script>
</body>
</html>
Hello,
Im trying to login on demo server through API.
API return success message:
...but account doesn't seems to be logger-in:
Is there any kind of restrictions on Demo server?
Thank you,
AM.