我使用jquery-select2来用ajax加载数据。但是jquery-select2 2也将空参数发送到控制器操作。
下面是用于搜索数据的agent.js代码
$('.chosen-select').select2({
minimumInputLength: 2,
placeholder: "Search by Agency code, agent code, name or email",
ajax: {
url: "/dashboard/agent_invitations/search_agents",
dataType: 'json',
type: 'GET',
data: function (term) {
{
q: term }
},
processResults: function (data) {
results: data.results
}
}
}); agents_controller.rb
def search_agents
respond_to do |format|
format.json {render json: { "data": current_salesperson.search_agents(params[:q]) }} //problem is here
end
end我遵循这个链接远程数据负载来加载远程数据,任何人都可以帮我这个忙。谢谢
发布于 2017-11-07 05:43:12
在数据中丢失返回
$('.chosen-select').select2({
minimumInputLength:2,
placeholder:"Search by Agency code, agent code, name or email",
ajax:{
url:"/dashboard/agent_invitations/search_agents",
dataType:'json',
type:'GET',
data:function (term) {
return { q:term }
},
processResults:function (data) {
results:data.results
}
}
});https://stackoverflow.com/questions/47150489
复制相似问题