问题
I am using jquery-select2 to load the data with ajax. But jquery-select2 alwasy send null params to controller action
Here is the agent.js code that i am using to search the data
$('.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
I followed this link remote data load to load remote data Can anyone please help me with this. Thank you
回答1:
Missing return in data
$('.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/jquery-select2-always-sends-null-params-in-controller