Home > OS >  Shelly - ajax api call return always error
Shelly - ajax api call return always error

Time:11-09

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: enter image description here

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);
      });

}

CodePudding user response:

Where does the protocol field coming from? I don't see any declaration for the protocol field in the code. Add this line to your ajax function and try - var protocol = 'http'

CodePudding user response:

I have the same requirement and just can't find a solution. The Shelly JSON response is not displayed to me with Ajax or jquery and the request is blocked with "Access-Control-Allow-Origin" despite the "Header".

  • Related