jQuery 的 Ajax 应用

JSON 调用:
action 方法:

public ActionForward json(ActionMapping mapping, ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("Entering 'json' method");
}
// json 数据
response.setContentType("application/x-javascript;charset=UTF-8");
//response.setContentType("text/plain;charset=UTF-8");
//response.setHeader("content-type", "text/plain;charset=UTF-8");
response.addHeader("Cache-Control", "no-cache");
JSONObject json = new JSONObject();
json.put("xx", maintenanceQuality.getXx());
json.put("yy", maintenanceQuality.getYy());
PrintWriter out = response.getWriter();
out.write(jsonMaintenanceQuality.toString());
return null;
}
}


function json(id) {
var url = "url?id="+id;
$.getJSON(url,function(data){
$("#xx").empty().append(data.xx);
$("#yy").empty().append(data.yy);

});
}


Ajax 调用:

public ActionForward ajax(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
if (log.isDebugEnabled()) {
log.debug("Entering 'getAssessmentResultById' method");
}
out.write("<h1>Hello World</h1>");
}
return null;
}


function ajax() {

$.ajax({
url:"url",
cache:false,
success:function(html){
$("#result").html(html);
}
});
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值