使用ajax异步请求返回一个对象。
java code:
@RequestMapping({"getAstSingleWheelImg_bbs"+Constant.JSON}) @ResponseBody public Result getImgUrl(HttpServletRequest request, Model model, WheelChart chart)throws ParseException{ String userName = request.getParameter("userName"); System.out.println("userName:"+userName); String astroDate = request.getParameter("astroDate"); String astroHour = request.getParameter("astroHour"); String astroMin = request.getParameter("astroMin"); //略过部分代码 result.setSuccess(true); result.setDesc(show_imgUrl); System.out.println(show_imgUrl); return result; }
js code:
var a=$("#wheelImg"); $.ajax({ async:true, type:"post", contentType:"application/x-www-form-urlencoded", cache:false, url:request_url+"/getAstSingleWheelImg_bbs.jo", data:a.serializeArray(), dataType:"json", timeout:6000, beforeSend:function () { alert("正在处理请求,请稍后。。。。。"); }, success:function(result){ $("img_wheel").attr("src",result.desc); alert("success"); }, error:function(XMLHttpRequest, textStatus, errorThrown){ alert(XMLHttpRequest.status); alert(XMLHttpRequest.readyState); alert(textStatus); } });
不解释太多了,网上的资料一堆堆的解释ajax。我就backup code..ok..