黄色电影一区二区,韩国少妇自慰A片免费看,精品人妻少妇一级毛片免费蜜桃AV按摩师 ,超碰 香蕉

ajax異步讀取后臺傳遞回的下拉選項的值方法

jsp中html相關代碼

<tr>
  <td class="tdcell_word2">請選擇展會:</td>
  <td class="tdcell_word3" colspan="3">
<select name="select" id="jieci" onchange="getchange()">
<option value="">選擇展會</option>
</select>
<script language="javascript">
loadjieci('- 選擇展會 -');
</script>
<span style="color:red;">&nbsp;*
<span style="font-size:12px;color:red;" id="mesjieci">
   </td>

</tr>

js中相關代碼

<script language="javascript">

function loadjieci(str) {
/** 異步加載屆次 */
$.getjson("/dictsaction.do?actiontype=jieci",
function (responsedata, status) {
if (status != "") {
$("#jieci").empty();
$("<option/>").html("- 選擇展會 -").val("- 選擇展會 -").appendto("#jieci");
$(responsedata).each(function (n) {

$("<option/>").html(this.name).val(this.code).appendto("#jieci");

});
//默認顯示請選擇
$("#jieci").val(str);


} else {
alert("屆次加載失?。?);
}
});
}

</script>

struts-config.xml中相關配置

<!-- ajax異步加載字典 -->
<action path="/dictsaction" type="oa.sys016.oagzxxgl.action.dictsaction" scope="request" />

java后臺代碼

package oa.sys016.oagzxxgl.action;


import java.io.printwriter;
import java.util.arraylist;
import java.util.hashmap;
import java.util.list;
import java.util.map;


import javax.servlet.http.httpservletrequest;
import javax.servlet.http.httpservletresponse;


import net.sf.json.jsonarray;


import org.apache.struts.action.action;
import org.apache.struts.action.actionform;
import org.apache.struts.action.actionforward;
import org.apache.struts.action.actionmapping;
import cn.com.chx.bo.appbo;
/**
 * 通過ajax加載屆次選擇下拉列表的選擇項
 * @author liu
 *
 */
public class dictsaction extends action{
private appbo appbo = null;

@override
public actionforward execute(actionmapping mapping, actionform form,
httpservletrequest request, httpservletresponse response)
throws exception {
// 設置編碼
response.setcontenttype("application/json;charset=utf-8");
response.setcharacterencoding("utf-8");
printwriter out = response.getwriter();


appbo = new appbo();


try {


// 獲取actiontype
string actiontype = request.getparameter("actiontype");


if (actiontype != null && actiontype.equals("jieci")) { // 查詢屆次
string jiecijson = getjiecijson();
out.print(jiecijson);
}


} catch (exception e) {
e.printstacktrace();
} finally {
out.close();
}


return null;
}


private string getjiecijson() {
// 查詢屆次
list jiecilist;
try {
jiecilist = appbo.query("select id as code,zh_name as name from zh_gz_infox");


list<map<string, string>> lists = new arraylist<map<string, string>>();


if (jiecilist.size() > 0) {
for (int i = 0; i < jiecilist.size(); i++) {
map<string, string> maps = new hashmap<string, string>();
maps.put("code",
(string) ((hashmap) jiecilist.get(i)).get("code"));
maps.put("name",
(string) ((hashmap) jiecilist.get(i)).get("name"));

lists.add(maps);


}
}
// [{"id":"1","name":"cimt2015"},{"id":"2","name":"ccmt2016"}] 
jsonarray json = jsonarray.fromobject(lists);


return json.tostring();
} catch (exception e) {
e.printstacktrace();
}
return null;
}
}

以上這篇ajax異步讀取后臺傳遞回的下拉選項的值方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持碩編程。

相關文章