0

So I want to execute the following action. In swagger it works like this: enter image description here

I've done the following in my .js:

  static performAction(id, param, actionUrl) {
  return $.ajax({
     url: api.devices.url + id + actionUrl,
     method: "PUT",
     dataType: "json",
     timeout: api.timeout,
     data: param});
 } 

    ...
    //inside a function
    var act = "/setTemperature";
    var temp = "19";
    var arr = [temp];
    var pp = JSON.stringify(arr);

       //Perform action apparently fails and returns null                       
   api.devices.performAction(item.id, pp, act).done(function(data){ 
           status.nextElementSibling.innerHTML = nueva_temp + "°C"; //works ok
    });

So I'm assuming the format is wrong?? Why?

Flama
  • 772
  • 3
  • 13
  • 39
  • @phil umm I don't really find the answer on the other question – Flama May 16 '18 at 02:36
  • If you need to send JSON, you need to set `contentType: 'application/json'`. You can also set `processData: false` but that's optional – Phil May 16 '18 at 02:39
  • If it's still not working, I suggest you look at the request / response in your _Network_ console – Phil May 16 '18 at 02:40

0 Answers0