JQuery Ajax Get Info Show in drop down list

Source: Internet
Author: User

<link href= "${ctxstatic}/jquery-select2/4.0.3/select2.min.css" rel= "stylesheet"/>
<script src= "${ctxstatic}/jquery-select2/4.0.3/select2.full.min.js" type= "Text/javascript" ></script>
<script src= "${ctxstatic}/jquery-select2/4.0.3/i18n/zh-cn.js" type= "Text/javascript" ></script>


$ ("[data-toggle= ' tooltip ']"). ToolTip ({html:true});
Get the entire list
$ (' #primaryAuditUserId '). Select2 ({
Language: "ZH-CN",
Minimuminputlength:1,
PLACEHOLDER: "--Please enter the nickname search--",
Ajax: {
URL: "Xxx/xxx/xxxx/userall",
DataType: "JSON",
DELAY:500,
Data:function (params) {
Return {Name:params.term};//name is the ID of the incoming parameter
},
Processresults:function (res, params) {
var options = [];
Console.log ("Res:" +res);
$ (res). each (function (index, R) {
var option = {"id": r.id, "text": ID in r.name};//list, name in list
Options.push (option);
});
return {
Results:options
};
},
Escapemarkup:function (m) {
return m;
}
}
});

Get ID
(function () {
var id = $ ("#select2-userid"). Val ();
if (ID) {
$.get ("xxxxxx/xxxx/single/" + ID, function (result) {
if (result) {
$ ("#primaryAuditUserId"). HTML ("<option value=" + result.id + "' >" + result.name + "</option>");//
}
});
}
})();



<li>
<label>:</label> of the first trial person
<input type= "hidden" id= "Select2-userid" value= "${infodto.primaryaudituserid}"/>
<form:select path= "Primaryaudituserid" class= "Input-medium" ></form:select>
</li>

Interface:

Fuzzy matching list
@RequestMapping (value= "Userall")
@ResponseBody
Public list<user> getusers (String name) {
User User=new user ();
User.setdelflag ("0");
User.setname (name);
List<user> userlist=userdao.findlist (User);
if (userlist.size () <=0| | Userlist==null) {
return null;
}
return userlist;
}

Querying for individual IDs
@RequestMapping (value= "Singuser")
@ResponseBody
public string Getsingleuser (string name) {
User User=new user ();
User.setname (name);
User User_=userdao.getsingle (user);
return User_.getid ();
}

JQuery Ajax Get Info Show in drop down list

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.