java jsonp

xiaoxiao2021-02-28  106

java 后台程序:

@Controller public class TaskDetailController {

@ResponseBody @RequestMapping(value = "/test.json", produces = "text/html;charset=UTF-8") public String getTaskDetailByTaskId(String testId, HttpServletRequest request){

String callback = request.getParameter("callback"); if(null != callback){ String resultJsonp = callback + "(" + jsonObject.toString() + ")"; return resultJsonp; }else{ return jsonObject.toString(); }

}

}

前端程序调用代码:

ur3 = "http://ip:8080/balantflow/module/sf/test.json"          $.ajax({                type: "get",                //async: false,                url:ur3,   data: "testId=123",              dataType:"jsonp",   jsonp:"callback",              success:function(json){                    alert(json);                },                error: function(){                    alert('fail');                }            });  

转载请注明原文地址: https://www.6miu.com/read-43975.html

最新回复(0)