ajax 个人学习小记

来源:互联网 发布:包月无限流量软件 编辑:程序博客网 时间:2024/05/22 15:58

 


(一)跨域式

  java controller

    @RequestMapping("/openOrbit")
    @ResponseBody
    public void openOrbit(HttpServletRequest req,HttpServletResponse resp,x read) throws IOException{
        resp.setCharacterEncoding("UTF-8");
        resp.setHeader("Content-type", "text/html;charset=UTF-8");
        String jsoncallback=req.getParameter("jsoncallback");
        PrintWriter out = resp.getWriter();
        List<xx> list=tpShipTargetshipService.xxx(read, new RowBounds());
        JSONArray array = new JSONArray();
        long timeing=System.currentTimeMillis();
        for (xx s : list) {
            JSONObject jsonObject=new JSONObject();
            if(list.size()>0){
                jsonObject.put("a", a);
                jsonObject.put("b", b);
                jsonObject.put("ct", c);
                array.add(jsonObject);
            }
        }
        out.write(jsoncallback+"("+array+")");
    }
   




jsp

        $.getJSON(contextPath + '/openOrbit?q1='+q1+"&w1="+w1+"&jsoncallback=?").done(function(data){

                     if (data.length>0) {
                            addShipTrack(array);
                      }

            });