我遇到了JQuery ajax请求的问题,无法弄清楚我做错了什么。
当我在命令行发送curl时,它运行正常:
curl -XPOST http://127.0.0.1:3000/bridge/heatingCircuits/hc1/temperatureRoomManual -d '{"value":20}' -H 'Content-Type: application/json'
但是使用JQuery Ajax它不起作用:
$.ajax({
url: "http://127.0.0.1:3000/bridge/heatingCircuits/hc1/temperatureRoomManual",
type: 'POST',
dataType: 'json',
contentType: 'application/json',
processData: false,
data: '{"value":20}',
success: function (data) {
alert(JSON.stringify(data));
},
error: function(){
alert("Cannot get data");
}
});
我收到以下错误回复:
net::ERR_CONNECTION_REFUSED
答案 0 :(得分:0)
$.ajax({
url: "http://127.0.0.1:3000/bridge/heatingCircuits/hc1/temperatureRoomManual",
type: 'POST',
dataType: 'json',
//contentType: 'application/json',
data: {value:20},
success: function (data) {
alert(JSON.stringify(data));
},
error: function(){
alert("Cannot get data");
}
});