ajax 跨域处理 jsonp
来源:互联网 发布:什么是网络安全管理 编辑:程序博客网 时间:2024/04/28 09:51
前段页面 <script type="text/javascript">
$.ajax({
type: "get",
async: false,
url: 'http://shanghai.51fmzg.com/findNoticeMessage.htm',
dataType: "jsonp",
jsonp: "callback",
jsonpCallback:"flightHandler",
success: function(json){
$.each(json,function(idx,item){
$("div.notice ul").after("<li><div class='newtitle'>"+item.content+"</div><div class='time'>"+item.sendDate+"</div><div class='clear'></div></li>")
});
},
error: function(){
alert('fail');
}
});
});
</script>
服务端
public ModelAndView findNoticeMessage(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
List noticeMessageList = messageManager.findNoticeMessage(0, 3);
Collections.reverse(noticeMessageList);
List jsonList=new ArrayList();
String message="[";
for (int i = 0; i < noticeMessageList.size(); i++) {
Map map=(Map)noticeMessageList.get(i);
if(i>0){
message=message+",";
}
String string =map.get("sendDate").toString();
message+="{'content':'"+map.get("content").toString().trim()+"','sendDate':'"+map.get("sendDate").toString().substring(0,16)+"'}";
}
message+="]";
JSONArray ja = JSONArray.fromObject(noticeMessageList);
response.setContentType("text/plain");
PrintWriter out = null;
try {
out = new PrintWriter(new OutputStreamWriter(response
.getOutputStream(), "utf-8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String callback = request.getParameter("callback");
out.println(callback+"("+message+")");
out.flush();
out.close();
return null;
}
- ajax 跨域处理 jsonp
- ajax jsonp跨域处理
- ajax跨域系列--JSONP方式处理
- ajax的跨域处理之JSONP
- jquery 源码分析8-ajax(D)JSONP跨域处理
- jquery中的ajax处理跨域问题-之-----jsonp
- ajax跨域jsonp处理
- ajax 跨域 jsonp 处理
- ajax jsonp跨域调用
- ajax跨域请求jsonp
- jsonp ajax跨域访问
- ajax跨域访问jsonp
- ajax Jsonp 跨域原理
- Ajax跨域和JSONP
- AJAX - 跨域请求 && JSONP
- jsonp ajax跨域问题
- ajax跨域问题解决:JSONP
- Ajax Jsonp 跨域实例
- AOP原理
- Spring初始化之扩展xml配置文件
- Python中os模块功能
- AOP简单的核心代码
- Java在Mac OS、Unix/Linux、Windows中文本文件的换行符
- ajax 跨域处理 jsonp
- Android文件存储_A_文本文件_自定义 向SDCard上保存文件
- ARM开发板编译安装设备模块
- 二叉树非递归
- 2013年02月21日 工作总结
- 用openssl实现sm2算法文档中示例,包含sm3
- 只读方式打开sqlite数据库
- tomcat 登陆账号设置
- 机器学习10大经典算法