如何在React Native中使用Fetch发布表单?

Piyush Chauhan

我正在尝试使用react-native fetch api发布包含first_name,last_name,email,password和password_confirmation的表单。

fetch('http://localhost:3000/auth', {
  method: 'post',
  body: JSON.stringify({
    config_name: 'default',
    first_name: this.state.first_name,
    last_name: this.state.last_name,
    email: this.state.email,
    password: this.state.password,
    password_confirmation: this.state.password_confirmation,
  })
})

在Rails控制台中输出

Parameters: {"{\"config_name\":\"default\",\"first_name\":\"Piyush\",\"last_name\":\"Chauhan\",\"email\":\"[email protected]\",\"password\":\"diehard4\",\"password_confirmation\":\"diehard4\"}"=>"[FILTERED]"}
Unpermitted parameter: {"config_name":"default","first_name":"Piyush","last_name":"Chauhan","email":"[email protected]","password":"diehard4","password_confirmation":"diehard4"}

因此,将整个值发布为字符串和rails就是将字符串解析为变量。我想从json响应中删除“ {”。怎么做 ?

鲁勒

因此,如果我对您的理解很好,您是否希望它发布相同的字符串,但没有花括号?

如果是这样,您可以从字符串中删除它们。

.replace(/ {|} / gi,“”)

这样看起来如下

fetch('http://localhost:3000/auth', {
method: 'post',
body: JSON.stringify({
  config_name: 'default',
  first_name: this.state.first_name,
  last_name: this.state.last_name,
  email: this.state.email,
  password: this.state.password,
  password_confirmation: this.state.password_confirmation,
  }).replace(/{|}/gi, "")
})

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在react-native中使用fetch发布multipart / formdata?

无法在 React Native 中使用 Javascript 'fetch' 发布 JSON?

如何在 React-Native 或 Expo 的 fetch 中使用 headers

如何在React中使用获取和表单数据来发布对象?

如何在php中使用表单发布表格?

如何在表单中使用onclick发布变量

你如何在php中使用ajax发布表单?

如何在React Native中使用OpenCV

如何在 React Native 中使用容器?

如何在React Native中使用Elasticsearch?

如何在Typescript中使用React Native?

如何在React Native中使用Iframe?

如何在React Native中使用componentWillUnmount?

如何在 React Native 中使用 SVG?

如何在React Native中使用服务器实现发布/订阅功能

如何在与Jest的react-native中使用模拟的fetch()对API调用进行单元测试

无法在React Native中使用`fetch()`

如何在React Native中使用React.forwardRef()

如何在React / React Native中使用Emscripten编译的JavaScript

react native - 如何在元组数组中使用 React Hooks?

如何在React中使用fetch()API到setState

如何在 React 中使用 for/in 语句和 fetch()

如何在React中使用表单作为组件

如何在React Native中提交表单

发布多部分/表单数据时,React Native fetch 抛出错误

如何在React Native中使用动态样式类

如何在Typescript中使用react-native-web

如何在React Native中使用AnimatedCircularProgress正确放置视图

如何在Jest中使用NavigationEvents测试React Native组件