简体   繁体   中英

sending json data from rails form

I have a rails form, which has some fields.

Now i want to send values of these fields, converted to json to some url

I can traverse through each element of form, convert it into json(using javascript) prepare a json string and send a request to the server.[client side conversion]

Other approach can be, posting the form normally to some controller action. then reading the data on the rails controller. parsing it to json and sending to desired url[server side conversion]

But i dont think these are good approaches.

what can be better way to do this?

Why do you want to convert before sending to the server? You can easily generate JSON in Rails on the server side using the submitted POST data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM