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);
			}
		});
 }


你可能感兴趣的:(JavaScript,jquery,Ajax,json,cache)