案例效果

在JEPaaS跨域请求其他服务接口

实现思路

  1. 前台JS实现

  2. 后台逻辑实现

操作步骤

  1. 前台JS
 Ext.data.JsonP.request({
    url: 'http://192.168.20.2:8080/je/load1',//跨域的地址
    timeout: 300000,
    //参数
    params: {
    method: 'load1'
    },
    callbackKey: "callback",//callback参数
    success: function(result){
    JE.log(result)
    },
    failure: function (result) {
    }
    });
  1. 后台demo
 @RequestMapping(value = "/load1", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    @ResponseBody
    public void load1(MethodArgument param) {
        HttpServletRequest  request = param.getRequest();
        HttpServletResponse  response = param.getResponse();
        String cb = request.getParameter("callback");
        response.setContentType("application/x-json");
        PrintWriter out = null;
        try {
            out = response.getWriter();
        } catch (IOException e) {
            e.printStackTrace();
        }
            out.write(cb + "([{status:'success'}]");
            out.write(");");
    }
  1. 测试结果

关键字,相关问题

  • 跨域请求其他服务接口
最后编辑: 呼丽华  文档更新时间: 2024-04-28 13:13   作者:肖海杰