开发者

How could I send JSON object and get in return js code in rails 3.1?

开发者 https://www.devze.com 2023-04-10 06:42 出处:网络
I have a list of html input items in my html page each representing different model. On click of the submit button, I would like to send all the details as a json object to the controller. From the co

I have a list of html input items in my html page each representing different model. On click of the submit button, I would like to send all the details as a json object to the controller. From the controller, I would like to return the js code to the browser.

As far as the examples I have seen, they are either sending the data as json and receive json from the server else send the data using form_for and receive the js code from the server. But I wo开发者_如何转开发uld like to send json and receive back js code. How i can do this in rails 3.1 using jQuery?


I believe this Railscast by Ryan Bates provides detailed instructions for doing exactly what you are describing.

Railscast Episode #136 - JQuery

That was the railscast I used when I was first learning to post data using jquery in a JSON format and return javascript. It was really helpful.

Though the Rails version is not 3.1, you should be able to adapt the ideas quickly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号