开发者

Adding a like button to a post that doesn't refresh the page

开发者 https://www.devze.com 2023-03-08 06:10 出处:网络
I am trying to add a like button to a post in my RoR application. The two models I have are Post and Like.

I am trying to add a like button to a post in my RoR application. The two models I have are Post and Like.

On my webpage I am going to put the like button right next to the post button, but wh开发者_如何学运维en users click the like button, I would like to have th request run in the background and not have to refresh the page.

Does anyone know of a simple way I could do this or where I can learn more about how to do it?

I am using the jQuery JavaScript library in my Rails application.


If you're using jQuery, you should use the jQuery.ajax() method, or one of it's deriviatives depending on your purposes. It runs in the background, and is very easy to use.


You can use jquery's ajax

api here

http://api.jquery.com/jQuery.ajax/

or even this one

http://jqapi.com/#p=jQuery.ajax

0

精彩评论

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