|
使用EXT官方API提供的Ext.data.JsonP
注意:JSONP只支持get请求,对于平台后端来说,只需要把RequestMapping中的 method = RequestMethod.POST改成 method = RequestMethod.GET即可 1.前台JS - <font face="微软雅黑"> 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) {
- }
- });</font>
复制代码
2.后台demo - <font face="微软雅黑"> @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(");");
- }</font>
复制代码
3.测试结果
|
|