前端之家收集整理的这篇文章主要介绍了
jsonp 已测试,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
1、js中 $.ajax({ type:'post',dataType:'jsonp',url:'http://localhost:8080/by/a/yzm?verifycode=1234'+'&phone=18788990099',jsonp:'jsonpCallback',success:function(data){ alert(data); 2、
方法中 @RequestMapping(value = "/by/a/yzm") @ResponseBody public JSONPObject zym(Model model,HttpServletRequest request,HttpServletResponse response) { Map<String,String> param = new HashMap<>(); String phone = request.getParameter("phone"); String verifycode = request.getParameter("verifycode"); param.put("phone",phone); boolean check = true; param.put("source",""); param.put("validateCode",verifycode); String url = Resources.getString("crm.service.url"); String resut = "processing ..."; if (resut.indexOf("processing") > 0) { check = false; } return new JSONPObject(request.getParameter("jsonpCallback"),String.valueOf(check)); } 3、spring-dispatcher配置 <property name="defaultViews"> <list> <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" /> </list> </property> 注意 JSONPObject为import org.codehaus.jackson.map.util.JSONPObject;不要用错了
原文链接:https://www.f2er.com/json/289563.html