欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ajax异步请求返回对象

程序员文章站 2022-03-09 21:50:38
...

使用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..