• ajax异步请求返回对象


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

  • 相关阅读:
    Canal 实现 同步 到 MySQL 从库 库级镜像同步 含 DDL 语句
    电商数据分析常用业务指标
    XX学Python·面向对象
    XX学Python·字符串
    XX学Python·总结和推导式
    XX学Python·函数
    XX学Python·集合
    XX学Python·异常处理
    XX学Python·元组
    XX学Python·字典
  • 原文地址:https://www.cnblogs.com/youngjoy/p/3301135.html
Copyright © 2020-2023  润新知