jsonp 跨域

            $.ajax({ 
                url:"http://192.168.100.47:8080/ais-connect/data/newaisSyn",
                type:'GET', 
                dataType:'JSONP', 
                jsonp: 'callback',
                success: function(data){ 
                var myshipids=data;
                    console.log(data);
                    $.each(data,function(i,obj){
                          console.log(obj.MMSI);  
                    })
//                     console.log(123);
                },
                error: function(jqXHR, textStatus, errorThrown ){
                      console.log(textStatus);
                      console.log(errorThrown);
                }
            }); 






public  void newaisSyn() throws IOException{
        
        HttpServletRequest request = getRequest();
        
        HttpServletResponse response = getResponse();
        response.setHeader("Access-Control-Allow-Origin", "*");
        
//        response.setCharacterEncoding("UTF-8");
//        Writer out = response.getWriter();
//        System.out.println("dsds");
//        out.write("dsds");
        List<Record> list = Db.use("ais").find("SELECT  d.mmsi FROM T_SHIP_TRACK_RECENT d where rownum<=10");

        String callback = request.getParameter("callback");
        
        System.out.println("callback(" + JsonKit.toJson(list) + ")");
        // renderJson("callback(" + JsonKit.toJson(list) + ")");
        renderJson(String.format("%s(%s)", callback, JsonKit.toJson(list)));
    }

 

posted @ 2018-05-21 22:31  Rainyn  阅读(112)  评论(0编辑  收藏  举报