I use this code in my html page to post json data to server using toggle switch ( depending on the value of toggle switch)
$('#ledToggle').change(function () {
var ledState = $(this).prop('checked');
var body = {
//Key: "1",
LedState: ledState
};
console.log(body);
body1 = JSON.stringify(body);
console.log(body1);
return $.ajax({
type: "POST",
url: "http://localhost:8060/api/led",
data: JSON.stringify(body),
dataType: "json",
contentType: "application/json"
});
But it always give me response 405 "Method not allowed
" in Mozilla and "XMLHttpRequest cannot load http://localhost:8060/api/led. Response for preflight has invalid HTTP status code 405
" in Chrome.
And when I uses Postman or fiddler to post it posts normally.