3

I want to send a http put request to a api using jquery/js here is what i came up with

$.ajax({
type: 'PUT',
dataType: 'json',
url: "http://192.168.x.xxx/api/somerandomusername/lights/1/state",
headers: {"X-HTTP-Method-Override, Access-Control-Allow-Origin: *": "PUT"},
data: {"on":true, "sat":255, "bri":255,"hue":10000}
});

if i'm using the api debugging tool it's working so my url and data are good and i don't have anything showing up in the chrome console.

For more context here is my setup

i'm sending the request to a Philips/hue bridgeusing the url and telling the bulb number 1 this string of data "on":true, "sat":255, "bri":255,"hue":10000.

Arriflex
  • 145
  • 1
  • 2
  • 7

1 Answers1

2

You can try

$.ajax({
    headers: { 'custom-header': 'value' }
});

If you want to add a header (or set of headers) to every request then use the beforeSend hook with $.ajaxSetup():

$.ajaxSetup({
    beforeSend: function(xhr) {
        xhr.setRequestHeader('custom-header', 'value');
    }
});

and you can read on the header properties

http://www.w3.org/TR/cors/

and a possible duplicate

How can I add a custom HTTP header to ajax request with js or jQuery?

Community
  • 1
  • 1
Oli Soproni B.
  • 2,774
  • 3
  • 22
  • 47