2017-08-09 24 views
0

我正在做一個多重複選框過濾器,並且必須使用post方法向服務器發送一個對象。我如何使用抓取來做到這一點?我可以使用抓取發送數據嗎?並從服務器,我必須收到一個過濾列表。 謝謝!如何通過提交數據發送數據react-redux

+2

指定與「POST」

例如這裏的代碼獲取方法你應該能夠使用取。你試過什麼了? –

+0

你的問題現在太廣泛了,你會得到的可能的迴應是被問到,你已經嘗試過了嗎?您可能需要先閱讀https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch – sideshowbarker

回答

2

是的,你可以從https://facebook.github.io/react-native/docs/network.html

function getMoviesFromApiAsync() { 
    return fetch('https://mywebsite.com/endpoint/', { 
     method: 'POST', 
     headers: { 
     'Accept': 'application/json', 
     'Content-Type': 'application/json', 
     }, 
     body: JSON.stringify({ 
     firstParam: 'yourValue', 
     secondParam: 'yourOtherValue', 
     }) 
    }).then((response) => response.json()) 
     .then((responseJson) => { 
     return responseJson.success; 
     }) 
     .catch((error) => { 
     console.error(error); 
     }); 
    }