码迷,mamicode.com
首页 > 其他好文 > 详细

React-Native post和get请求

时间:2016-01-20 13:08:26      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

post:

 1 fetchData (title) {
 2     fetch(REQUEST_URL, {
 3     method: ‘POST‘,
 4     headers: {
 5     ‘Accept‘: ‘application/json‘,
 6     ‘Content-Type‘: ‘application/json‘
 7     },
 8     body: JSON.stringify({
 9       email: un,
10       password: pw
11     })
12   })
13     .then((response) => response.json())
14     .then((responseData) => {
15       if (responseData[‘isOK‘]===‘ok‘) {
16         ToastAndroid.show(‘登录成功‘, ToastAndroid.SHORT)
17       } else {
18         ToastAndroid.show(‘登录失败‘, ToastAndroid.SHORT)
19       }
20     })
21     .done()
22   }
1   responseData (response) {
2     return response.result.data
3   }

 

get:

 1 fetchData: function () {
 2     fetch(REQUEST_URL)
 3       .then((response) => response.json())
 4       .then((responseData) => {
 5         this.setState({
 6           dataSource: this.state.dataSource.cloneWithRows(responseData),
 7           loaded: true
 8         })
 9       })
10       .done()
11   },

 

React-Native post和get请求

标签:

原文地址:http://www.cnblogs.com/weifengzz/p/5144528.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!