0

I am trying to send a HTTP POST with JSON via jQuery to a local network app (Hue Emulator: http://steveyo.github.io/Hue-Emulator/) with this code:

$.post("http://localhost/api/newdeveloper/lights/6/state", "{\"on\": false}", function (data, textStatus, jqXHR) {
    console.log(data);
});

On the console of the app I see this response:

So, 12 Nov 2017 15:47:58   /api/newdeveloper/lights/6/state
So, 12 Nov 2017 15:47:58   {"on": false}

Which is the same as in this image: https://raw.githubusercontent.com/SteveyO/Hue-Emulator/master/screenshot.png

But I don't see any response and also the light bulb doesn't turn off visually in the emulator. Is there a problem with jQuery and sending localhost-POST requests? This is the result I see in Google Chrome:

enter image description here

With this approach:

$.ajax({
    type: "POST"
    , url: "http://localhost/api/newdeveloper/lights/6/state"
    , data: {
        "on": false
    } // or {"on": true} 
}).done(function (data, textStatus, jqXHR) {
    console.log(data);
});

I get: enter image description here

binaryBigInt
  • 1,526
  • 2
  • 18
  • 44

1 Answers1

3

use $.ajax like this:

$.ajax({
    type: "POST",
    url: "http://localhost/api/newdeveloper/lights/6/state",
    data: {"on": false} // or {"on": true} 
}).done(function (data, textStatus, jqXHR) {
    console.log(data);
});

return value log in console

VMT
  • 191
  • 10
  • add dataType: "json" to $.ajax after data option – VMT Nov 12 '17 at 15:45
  • according to [document](https://developers.meethue.com/documentation/lights-api) in this section **1.6. Set light state** set light state use _PUT_ method – VMT Nov 12 '17 at 15:52