日期:2014-05-16 浏览次数:20686 次
import org.json.JSONObject;
//result、username的setter、getter方法
public String showUser(){
List list = userDAO.findByUsername("king");
System.out.println("userame"+userame);
JSONObject obj=new JSONObject();
try {
obj.put("users", list);
result=obj.toString();
System.out.println("result: "+result);
//显示:result: {"users":[{"userpassword":"king","username":"king","userid":1}]}
} catch (JSONException e) {
e.printStackTrace();
}
return Action.NONE;
//return SUCCESS;//换成这句js不能弹窗
}
<package name="userpk" extends="json-default" >
<action name="user" class="userAction">
<result type="json" name="result">
</result>
<!-- <result type="json">
<param name="root">result</param>
</result> -->
</action>
</package>
<script type="text/javascript">
$(document).ready(function(){
$("#btn").click(function(){
$.ajax({
type: "POST",
url: "user!showUser",
dateType: "json",
data: {"userame":"wang"},
success: function(data,status){
//var json = eval( "("+result+")" );
//alert("json"+json);
alert("result:"+data);
alert("status:"+status);
}
});
});
});
</script>
import org.json.JSONObject;
//result、username的setter、getter方法
public String showUser(){
List list = userDAO.findByUsername("king");
System.out.println("userame"+userame);
JSONObject obj=new JSONObject();
try {
obj.put("users", list);
result=obj.toString();
System.out.println("result: "+result);
&n