Rails 3: How to make an Ajax call?

前端 未结 2 1082
北恋
北恋 2020-12-30 06:35

I would like to have a link (is there a better option?) on my page which will make an Ajax request when clicked. (I would like to update a field in my database when the link

2条回答
  •  半阙折子戏
    2020-12-30 06:53

    You're really going to be using two technologies to accomplish this: javascript on the client-side, and rails on the server-side.

    The general idea is that you want to:

    (1) add your web methods on the server side with rails, and then
    (2) use something like jQuery to get your client-side js calls up to the server to fire off the web methods.

    Two writeups I found by googling for : rails3 ajax

    http://www.stjhimy.com/posts/7-creating-a-100-ajax-crud-using-rails-3-and-unobtrusive-javascript

    http://www.simonecarletti.com/blog/2010/06/unobtrusive-javascript-in-rails-3/

    API Reference for using jQuery's ajax post() method:
    http://api.jquery.com/jQuery.post/

提交回复
热议问题