首页 > 解决方案 > 为什么 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 客户端

标签: javascriptjqueryajaxreact-nativeexpo

解决方案


ReactJS/React Native 使用虚拟 DOM 不像 jQuery 依赖 HTML DOM,所以它不能在 React Native App 中工作。

您可以使用fetchapi 或axios代替。

你可以在这里阅读更多关于它的信息:Can react native use jQuery


推荐阅读