javascript - 为什么 onPress 不能在世博客户端上工作
问题描述
我正在尝试在按下按钮时使用 jQuery 发送请求,它正在处理零食,但在 expo 客户端上它给了我一个错误undefined is not a function (near '...jquery.default.ajax...')
,但它没有在网络上给我这个
这是代码:
<Button title='Submit' onPress={() => {
$.ajax({
url: 'https://modern-clinic.herokuapp.com/new/case',
type: 'POST',
data: {
name: this.state.name,
paid: this.state.price,
description: this.state.desc,
assigned: this.state.assigned,
date: this.state.date
},
success: function(res){
console.log(res)
},
error: function(err){
console.log('error')
console.log(err)
}
})
}}/>
</View>
)
}
}
export default New
将您想要的数据放入其中但付费应该是一个数字
它在网络上运行良好并按应有的方式发送请求,但在 expo 客户端上,尤其是对于 android,它不起作用,但我没有尝试 IOS 的 expo 客户端
解决方案
ReactJS/React Native 使用虚拟 DOM 不像 jQuery 依赖 HTML DOM,所以它不能在 React Native App 中工作。
您可以使用fetch
api 或axios
代替。
你可以在这里阅读更多关于它的信息:Can react native use jQuery
推荐阅读
- java - 如何限制从 1895 年到 2021 年范围内编辑文本的输入
- python - 坚持使用 Python if-else 一行语句
- laravel - Laravel Livewire 点击提交
- javascript - 当使用javascript满足某些条件时,有没有办法停止监听事件?
- java - 为什么我的猜谜游戏没有出错但无法正常运行?
- go - 在本地机器上运行第一个 Go 项目时出错
- c++ - C++14 与 C++17 的部分专业化差异?
- apache-spark - 写入时的 AWS Glue 性能
- javascript - 在 Cypress 测试中读取 XML 文件内容
- php - Wordpress 阻止所有引用 upload_max_filesize 指令的媒体,但这是不正确的