2015-12-24 28 views
0

我需要檢查某個鍵/值對是否到達Node應用程序。該鍵的值在角度應用程序的輸入字段中鍵入。我有點卡住了,有人可以幫忙嗎?也許一直盯着這太長了......獲取發送的JSON值的值

var button_sendtext = JSON.stringify([{"key":"sendtext","value":" this will be a variable text "}]) 
if(message == button_sendtext) { 
    request // do request to internal webserver 
    .get('http://thisisjusttesturl/api', function (error, response, body) { 
    if (!error && response.statusCode == 200) { 
     console.log(response); 
     console.log(body); 
    } else { 
     console.log('Error!'); 
    } 
    }); 
} 

UPDATE:

我作出這個應用程序,一部分是科迪遠程,我在輸入字段中鍵入發送到科迪API文本通過經紀人。 A GET請求的作品,所以這不是問題。節點應用程序需要解釋通過應用程序發送的文本。現在,我正在檢查固定鍵和值。希望這可以澄清事情...

+0

你不應該使用'後'發送JSON到服務器? –

+1

你想要Node還是Angular?如果是Angular,那麼你在服務/工廠有什麼功能?你在控制器中有什麼?如果它是一個Node問題,那麼添加標籤'node.js'而不是'angular'。 –

+0

我很困惑這個問題是什麼......問題是什麼?該網址看起來不對。 – ragerory

回答

0

我一直在爲此磨合我的大腦。這是我如何解決它:

var button_sendtext = message; 
function stringStartsWith (string, prefix) { 
    return string.slice(0, prefix.length) == prefix; 
} 
if(stringStartsWith(button_sendtext, '[{"key":"sendtext"')) {