Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
132
rated 0 times [  135] [ 3]  / answers: 1 / hits: 16248  / 9 Years ago, fri, june 5, 2015, 12:00:00

I'm trying to post the form containing the first_name, last_name, email, password and password_confirmation using react-native fetch api.



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,
})
})


Output in Rails console



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}


So, its posting the whole value as string and rails is parsing the string as a variable. I want to strip out the { from the json response. How to do it ?


More From » reactjs

 Answers
46

so if I understand you well, you want it to post the same string but just without the curly braces?



If that's the case, you can just strip them from the string.




.replace(/{|}/gi, )




so that would look as follows



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, )
})

[#66315] Wednesday, June 3, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
danae

Total Points: 26
Total Questions: 97
Total Answers: 112

Location: Oman
Member since Wed, Apr 12, 2023
1 Year ago
;