I've developed a graphich interface for check all smart device in my home, but when I try to make a ajax call to shelly api for check the device status I get always error. If I utilize postman I able get the json result, but when make the same call in ajax not.
I use jquery 3.6.1 version and the authentication in my device is disabled.
The documentation is: https://shelly-api-docs.shelly.cloud/gen1/#shelly-motion-2
Can you help me?
The ajax call with postman:
This is my code:
function getMovementStatus(obj) {
//http://192.168.68.103/status
var url = protocol + '://' + obj.ip + '/status';
var settings = {
"url": url,
"method": "GET",
"timeout": 0,
"contentType": 'application/json'
};
$.ajax(settings)
.done(function (response) {
console.log(response);
})
.fail(function (request, error) {
console.log(error);
});
}
Where does the
protocol
field coming from? I don't see any declaration for theprotocol
field in the code. Add this line to your ajax function and try -var protocol = 'http'