2016-11-08 46 views
0

我有一個JQuery ajax請求的問題,無法弄清楚我做錯了什麼。curl xpost with jquery

當我在命令行上發送一個捲曲它是工作的罰款:

curl -XPOST http://127.0.0.1:3000/bridge/heatingCircuits/hc1/temperatureRoomManual -d '{"value":20}' -H 'Content-Type: application/json' 

但使用jQuery阿賈克斯它不工作:

$.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

迴應是:{「status」:「ok」} –

+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"); 
    } 
}); 
+0

現在我做了,但同樣的問題。 –

+0

您是否試圖用主機名替換http://127.0.0.1? – Fky

+0

或嘗試刪除ajax @MelisDekker中的contentType指令我編輯我的文章;) – Fky