标签:style http java 使用 os 数据 io 问题
$.get()和$.post()这两个方法,顾名思义,一个就是通过get方法来获取数据,另外一个通过post方法来获取数据。这两个方法在具体有什么区别呢?重点有三个方面的区别,第一个get传送的数据理论在2KB之内,post方法原则上是不受限制的。第二个方面,一个在地址栏上会显示当前的请求内容,这种在有用户名和密码的时候就不好了。另外一个是在请求体当中,这个虽然也不是很安全,但是至少要比GET方法要安全那么一点点了。第三个,其实get方法最初是用来设计请求静态内容的,而POST则是用来提交增删改数据的,只是后来的这个区分没那么明显而已了。Server端的代码如下:
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String name = req.getParameter("name");
String address = req.getParameter("address");
StringBuffer sb = new StringBuffer();
sb.append("<div><span>hi! nice to meet you! ");
sb.append(name).append(",(");
sb.append(address).append("),");
sb.append("how are you getting along?</span></div>");
StringBuffer xmlSb = new StringBuffer();
xmlSb.append("<book>")
.append("<title>")
.append("No ventured No gained")
.append("</title>")
.append("<publish>")
.append("Chinses publish")
.append("</publish>")
.append("</book>");
//resp.setContentType("text/html;charset=utf-8");
resp.setContentType("text/xml;charset=utf-8");
resp.getWriter().print(xmlSb.toString());
}
前端的代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript" src="jquery-1.8.3.js"></script>
<script type="text/javascript">
$(function(){
$("#getContentByAjax").click(function(){
//$.post("test",{name:"czz",address:"address"},callBack,"html");
//$.get("test",{name:"czz",address:"address"},callBack,"html");
$.get("test",{name:"czz",address:"address"},callBack,"xml");
});
function callBack(data,textStatus){
//$("#showText").html(data);
var title=$(data).find("title").text();
var publish = $(data).find("publish").text();
$("#showText").text(title+" "+publish);
}
});
</script>
</head>
<body>
<div id="showText"></div>
<input type="button" id="getContentByAjax" value="sendAjax">
</body>
</html>
jQuery_review之通过$.get()和$.post()方法来实现异步加载,布布扣,bubuko.com
jQuery_review之通过$.get()和$.post()方法来实现异步加载
标签:style http java 使用 os 数据 io 问题
原文地址:http://blog.csdn.net/ziwen00/article/details/38177925