【发布时间】:2011-07-30 23:15:00
【问题描述】:
我正在尝试在我的 rails 应用程序中使用 Jquery-UI 自动完成功能。在我的 application.js 里面我有一行
$j('#autocomplete').autocomplete({
source:'contexts/1.json'
});
根据我在文档中阅读的内容,该函数需要 json 数据作为回报,因此在我的 context_controller Show 方法中,我有以下内容
def show
@context = Context.find(params[:id])
if params[:term]
@tags = Tag.find(5, :conditions => ['name LIKE ? AND context_id = ?',params[:q], @context.id])
else
@tags = Tag.find(:all, :conditions => ["context_id = ?",@context.id])
end
respond_to do |format|
format.html
format.json { render :json => @tags}
end
结束
问题是,当我开始在自动完成附加到的输入框中输入内容时,服务器似乎没有收到请求。我怎样才能使这项工作?
【问题讨论】:
-
什么是 $j('#autocomplete')?是 $('#autocomplete') 吗?还有一些萤火虫或其他东西的错误呢?
-
对不起,我不得不使用 'var $j = jQuery.noConflict();'因为我也使用原型。 firebug 中没有错误。
-
您是否尝试过使用 Fiddler 或 Wireshark 之类的工具来确保将请求发送到服务器?而且,会得到什么样的回应?
-
您的页面上是否有带有 id="autocomplete" 的文本框?
标签: ruby-on-rails jquery-ui autocomplete