我正在使用Ruby on Rails,並且我想調用控制器方法作爲我的預先存在的鏈接的onclick
事件。使用jQuery AJAX在客戶端調用Rails服務器方法
我正在使用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>
但這不是工作.. 的任何解決方案,將不勝感激。