日期:2014-05-16 浏览次数:20261 次
private String jsonResult; public String ajaxAllNames(){ jsonResult = categoryManager.getAllCategoryName(); return SUCCESS; }
public String getAllCategoryName(){ List<String> names = toolCategoryDao.getAllNames("select name From ToolCategory t"); return JSONArray.fromObject(names).toString(); }
<package name="ajax" namespace="/" [color=red]extends="json-default">[/color] <action name="ajaxCategoryName" class="com.wildrain.stm.action.ToolCategoryAction" method="ajaxAllNames"> <result type="json"> <param name="root">jsonResult</param> </result> </action> </package>
测试:<select id="se"></select>
$( function() { var url = 'ajaxCategoryName.action'; //使用$.post方式 $.post( url, //服务器要接受的url dealData, 'json' //数据传递的类型 json }); tion dealData(data){ alert(data); var tool = eval("("+data+")"); hasDataToDeal2(tool); } function hasDataToDeal2(data){ var se = $("#se"); $.each(data, function() { var opt = "<option value="+this+" >"+this+"</option>"; se.append(opt); //alert(this); }); }