ajax跨域获取返回值

时间:2019-03-12 10:03:12   收藏:0   阅读:272

js代码

$.ajax({ 
         async:false, 
            url: ‘https://***/api/prepareApi.getDanMu?sqlMapId=findBarrage‘,  // 跨域URL
            type: ‘get‘, 
            dataType: ‘jsonp‘, 
            jsonp: ‘jsoncallback‘, //默认callback
            jsonpCallback: ‘handleResponse‘, //设置回调函数名
            //data: mydata, 
            timeout: 5000,
            success: function(data){
              }
            
            
      }});

 

后台代码 (返回时 转json格式,括在js自定义回掉函数名里)

@RequestMapping("api/prepareApi.getDanMu")
    public String getDanMu() throws Exception {
        Map<String, Object> map = getParameterMap();
        System.out.println("api/prepareApi.getUserUploadWeiKeTeachApi: " + map);
        
        map.put("sqlMapId", map.get("sqlMapId").toString());
        
        List<Map<String, Object>> list = openDap.queryForList(map);
        
        return "handleResponse(" +  JSONArray.parseArray(JSON.toJSONString(list)) + ")";
    }

 

原文:https://www.cnblogs.com/remember-forget/p/10514728.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!