Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $("button").click(function(
- id = $(this).attr("id");
- toggle(id);
- ));
- function toggle(id)
- {
- var username = "username";
- var password = "password";
- $.ajax(
- {
- url:'http://myname.ddns.net:port/api/devices/' + id,
- type: 'get',
- dataType : 'json',
- contentType: 'application/json',
- async: true,
- beforeSend: function(xhr) {
- xhr.setRequestHeader('Authorization', 'Basic ' + btoa(username + ':' + password));
- },
- success: function(data)
- {
- if(data.properties.value == "true")
- {
- $("#25").attr("src","../assets/images/icons/switch/off.png");
- $.ajax(
- {
- url:"http://myname.ddns.net:91/api/devices/" + id +"/action/turnOff",
- type: 'post',
- dataType : 'json',
- contentType: 'application/json',
- async: true,
- beforeSend: function(xhr)
- {
- xhr.setRequestHeader('Authorization', 'Basic ' + btoa(username + ':' + password));
- },
- })
- }
- else if(data.properties.value == "false")
- {
- $("#25").attr("src","../assets/images/icons/switch/on.png");
- $.ajax(
- {
- url:'http://myname.ddns.net:port/api/devices/"+id+"/action/turnOn',
- type: 'post',
- dataType: 'json',
- contentType: 'application/json',
- async: true,
- beforeSend: function(xhr)
- {
- xhr.setRequestHeader('Authorization', 'Basic ' + btoa(username + ':' + password));
- },
- })
- }
- }
- },3000)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement