52,797
社区成员
发帖
与我相关
我的任务
分享
<script src="jquery/jquery.js" type="text/javascript"></script>
<script src="jquery/jquery.json-2.2.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
function doAjax() {
$.ajax({
type: "post",
url: "ajaxAction.action",
cache:false,
dataType:'json',
success: function(data) { alert($.evalJSON(data).info);},
error:function(){alert('error');}
});
}
</script>
public class AjaxAction extends ActionSupport {
@Override
public String execute() throws Exception {
HttpServletResponse resp = ServletActionContext.getResponse();
//resp.setContentType("application/json;charset=utf-8");
resp.getWriter().write("{total:100,info:\"ttttttttt\"}");
return NONE;
}
}
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("application/x-javascript;charset=UTF-8");
response.getWriter().write("{\"result\":\"OK!\"}");
<action name="delLogins" class="LoginManager" method="delLogins"></action>
$.ajax({
type : "POST",
url : url,
data : {"ids": ids},
dataType : "json",
success : function(data){
alert(data.result);
}
});