Jquery ajax 绑定multiselect多选下拉选项,同时异步执行返回值
Jquery ajax 绑定multiselect多选下拉选项,同时异步执行获取返回值
1 function load(mslt_employees,belongto,mark) {//传入$(#ID) 2 var jsondata = JSON.stringify({ belongto: 1, username: username }); 3 var emp = null; 4 jQuery.ajax({ 5 type: 'POST', 6 url: "../tools/employees_ajax.ashx?action=" + action + "", 7 dataType: "json",//返回JSON对象 8 data:jsondata,//上传JSON格式的参数 9 cache: false, 10 async:false,//异步执行 11 success: function (message) { 12 mslt_employees.empty();//清空下拉标签 13 if (message != "0" && message != "none") { 14 var list = message; 15 for (var i = 0; i < list.length; i++) { 16 if (mark == 1) { 17 if (belongto != 1) {//设置默认选项 18 mslt_employees.append($("<option value='" + list[i].USERNAME + "' disabled = 'disabled'>" + list[i].USERNAME + "</option>")); 19 } else { 20 mslt_employees.append($("<option value='" + list[i].USERNAME + "'>" + list[i].USERNAME + "</option>")); 21 } 22 } else { 23 mslt_employees.append($("<option value='" + list[i].USERNAME + "'>" + list[i].USERNAME + "</option>")); 24 } 25 if (i == 0) { emp = list[i].USERNAME; } else { 26 emp = emp + "," + list[i].USERNAME; 27 } 28 } 29 } 30 mslt_employees.multiselect('refresh');//刷新多选下拉标签 31 }, error: function () { return null; } 32 }); 33 return emp;//返回值 34 }
原文出处:http://www.cnblogs.com/OnlyDreams/p/4143515.html
转载请保留此链接