2017-08-09 66 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); 
     }); 
    }