要实现AJAX调用控制器在轨操作 [英] making an ajax call to controller action in rails
问题描述
我试图使一个Ajax调用我的控制器
I am trying to make an ajax call to my controller
class PatientRecordController < ApplicationController
def export
....
end
end
在我的JavaScript文件中,我有
In my javascript file i have
$(document).ready(function(){
freezeTopRow($('#dataTable'));
$("#export").click(function(){
$.ajax({url: "patient_record/export", type: "POST"});
});
});
当我检查元素和调试,当我点击我的页面导出标签。我打的功能但它从来没有得到到控制器
when i inspect element and debug and when i click the export tag on my page. i hit the function however it never gets to the controller
另外,我有2个控制器和2次。在我的其他控制器和视图我做同样的事情,它的工作原理
Also I have 2 controllers and 2 views. In my other controller and view I do the same thing and it works
推荐答案
你检查,你 routes.rb中
碰到这样的:
Have you checked that you routes.rb
have something like:
post 'patient_record/export'
也许Rails的不知道路线,以便阿贾克斯不工作(如果你能得到从浏览器的动作就意味着你只有一个 GET
集,你可以检查,改变在Ajax调用请求的类型)
Maybe Rails doesn't know the route so the ajax isn't working (if you can get to the action from your browser it means that you have only a GET
set, you can check that changing the type of the request in the ajax call)
这篇关于要实现AJAX调用控制器在轨操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!