jquery前台处理: var param = {a:a}; $.post("*.do",param,function(data) { var columHtml = ""; $.each(data, function(i, item) { columHtml = columHtml + "<option value=‘"+item[0]+"‘>"+item[1]+"</option>" }); $("#columnid").append(columHtml); }); 后台:返回json 格式 ========================================================================================================================= prototype.js使用ajax级联: 后台返回json格式的list,前台使用ajax 处理json 和 list 前台页面: <select name="id" id="id" onchange="aa(this.value)"> <option value="0">请选择</option> </select> js方法 function aa(id){ function onSuccess(response) { var data = response.responseText.evalJSON(); var colList = data.dataList; var columHtml = ""; for(var i = 0;i<colList.length;i++){ columHtml = columHtml + "<option value=‘"+colList[i].id+"‘>"+colList[i].colName+"</option>" } alert(columHtml); var a = $(‘columnid‘); alert(a.innerHTML); $(‘columnid‘).innerHTML = columHtml; } function onFailure(response) { alert(‘数据请求异常‘); } var params = "&websiteId="+websiteid; ajax = new Ajax.Request( ‘a.do‘,{ method: ‘POST‘, asynchronous: true, parameters:params, onSuccess : onSuccess, onFailure : onFailure } ); } 后台action处理: JSONObject jsonObject = new JSONObject(); jsonObject.put("dataList", maplist); this.getPrintWriter(jsonObject); xml处理: <action name="a" class="AAction" method="a"> <result name="success" type="json"></result> </action>
时间: 2024-10-14 04:19:35