我正在使用 Ruby on Rails,并且我想调用一个控制器方法作为onclick
我预先存在的链接的事件。
我正在使用 jQuery 和 AJAX 来做同样的事情。但是我对AJAX了解不多。
这是我的代码。
<script type="text/javascript">
$("a.browse_history").live("click", function()
{
alert("i am here");
$.ajax({
url: "/user_profile_controller.rb/save_user_history",
type: 'PUT'
});
});
</script>
在user_profile_controller.rb
:
def save_user_history
$doc_list << "hello hi"
end
我的链接是:
<a href="http://localhost:3000/documents" id="browse_history" class="browse_history">Click here</a>
但这不起作用..任何解决方案将不胜感激。