我在html页面中使用此代码,使用切换开关将json数据发布到服务器(取决于切换开关的值)
$('#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"
});
但它始终给我回复405" Method not allowed
"在Mozilla和" XMLHttpRequest cannot load http://localhost:8060/api/led. Response for preflight has invalid HTTP status code 405
"在Chrome中。
当我使用Postman或fiddler正常发布帖子时。