在application.js我有: $("#combo_box").live('change', (function() { $.ajax( { url: '/my_controller/get_data', data: {id: some_id}, success: function(data){ do_stuff_with_data(data) } } ) } ) ) 在my_controller代码中我有: def get_
$("#combo_box").live('change', (function() { $.ajax( { url: '/my_controller/get_data', data: {id: some_id}, success: function(data){ do_stuff_with_data(data) } } ) } ) )
在my_controller代码中我有:
def get_data id = params[:id] @data = MyModel.DoSomeStuff(id) respond_to do |format| format.js { render :json => @data} end end
但由于某种原因,成功的功能只运行一次(我认为),其余时间Firebug在组合框更改触发ajax调用时报告304 Not Modified.
这是如何运作的?谢谢!
$.ajax
的默认方法是GET:
type String
Default: ‘GET’
所以你的$.ajax调用正在执行GET请求,有人可能正在缓存它.尝试将cache:false添加到$.ajax选项中:
cache Boolean
Default: true, false for dataType ‘script’ and ‘jsonp’
If set tofalse
, it will force requested pages not to be cached by the browser.