关于React Native 网络请求以及变量赋值的问题
来源:互联网 发布:巨人网络官网 编辑:程序博客网 时间:2024/05/01 18:26
//初始化赋值
constructor(props){
super(props);
this.state = {
sid:"",
pla:"说点什么吧?"
};
}
//调用函数,需要绑定this,以免在函数中无法引用当前this
render() {
return (
<View>
<View style={styles.box}>
<ToolbarAndroid
style={styles.toolbar}
title="AwesomeApp"
actions={[{title: 'Settings',icon: require('./images/article.png'), show: 'always'}]}
onActionSelected={this.AjaxPost.bind(this)}
/>
</View>
<View style={styles.box}>
<TextInput style={styles.comment} placeholder={this.state.pla} keyboardType="default" multiline />
</View>
</View>
)
}
AjaxPost(){
//调用外部的this
var _this=this;
fetch('http://file.midasjr.com/play/user/login', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
},
//form格式上传参数,需要以"key=value&key=value"形式
body: 'phone=15601815671&password=123123&sid=""&rid=4&deviceid=D14448888832484539'
})
.then((response) => response.text())
.then((responseText) => {
//解析返回的json
var back=JSON.parse(responseText);
//变量重新赋值
_this.setState({sid:back.sid,pla:back.msg});
})
.catch((error) => { alert("错误"); alert(error); }) }
constructor(props){
super(props);
this.state = {
sid:"",
pla:"说点什么吧?"
};
}
//调用函数,需要绑定this,以免在函数中无法引用当前this
render() {
return (
<View>
<View style={styles.box}>
<ToolbarAndroid
style={styles.toolbar}
title="AwesomeApp"
actions={[{title: 'Settings',icon: require('./images/article.png'), show: 'always'}]}
onActionSelected={this.AjaxPost.bind(this)}
/>
</View>
<View style={styles.box}>
<TextInput style={styles.comment} placeholder={this.state.pla} keyboardType="default" multiline />
</View>
</View>
)
}
AjaxPost(){
//调用外部的this
var _this=this;
fetch('http://file.midasjr.com/play/user/login', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
},
//form格式上传参数,需要以"key=value&key=value"形式
body: 'phone=15601815671&password=123123&sid=""&rid=4&deviceid=D14448888832484539'
})
.then((response) => response.text())
.then((responseText) => {
//解析返回的json
var back=JSON.parse(responseText);
//变量重新赋值
_this.setState({sid:back.sid,pla:back.msg});
})
.catch((error) => { alert("错误"); alert(error); }) }
0 0
- 关于React Native 网络请求以及变量赋值的问题
- React Native网络请求
- React Native 网络请求
- React-Native中网络请求的总结
- React-Native中网络请求的总结
- React-Native中网络请求的总结
- react native 使用fetch进行网络请求(https),解决SSLHandshake问题,以及怎样进行二次封装
- react native 的赋值比较,空字符串以及undefined
- React-Native中网络请求
- React-native fetch请求网络
- React Native Fetch网络请求
- React-Native加载网络图片的问题
- React-Native Fetch网络请求的简单封装
- 添加布尔量的React Native fetch网络请求库。
- react-native网络请求Fetch中遇到的坑
- React Native -21.React Native Fetch网络请求
- react-native(Fetch网络请求数据)
- React Native之组件请求网络数据
- ListView 或是 GridView中。Canvas: trying to use a recycled bitmap 异常
- 【转】 java 运算符优先级
- 《统计学习方法》学习笔记--k近邻法及常用的距离(or 相似度)度量
- 纯代码封装自定义View和XIB封装自定义View的区别
- float类型在内存中的存储
- 关于React Native 网络请求以及变量赋值的问题
- 用SugarORM快速开发需要同步和保存大量数据的Android互联网客户端
- Android自定义类似ProgressDialog效果的Dialog
- Git之(三)Git辅助命令
- css对上传按钮美化
- ajax向服务端发送请求的简单使用
- 笔记本自带键盘输入错乱
- C++中的string类的用法
- SystemUI下拉通知栏和下拉快捷设置栏的对应设置