jquery-select2 always sends null params in controller

折月煮酒 提交于 2019-12-24 18:00:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!