81,092
社区成员
发帖
与我相关
我的任务
分享
// 打开输出
public void openWriter(HttpServletResponse resp) {
try {
resp.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
out = resp.getWriter();
} catch (IOException e) {
MyUtil.printInfo("---------------------------openWriter IOException--------------------------------------- ");
e.printStackTrace();
}
}
// 关闭输出
public void closeWriter() {
if (out != null) {
out.flush();
out.close();
}
}
out.print("要输出的信息。。。");//这个就是respone<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>
xxx
</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script type="text/javascript">
jQuery(document).ready(function() {
$.ajax({
type: "get",
async: false,
data: {
},
url: "http://www.geonames.org/postalCodeLookupJSON?postalcode=10504&country=US",
dataType: "jsonp",
jsonp: "callback",
success: function(json) {
for (var e in json.postalcodes[0]) {
document.write(e + "--->" + json.postalcodes[0][e]+"<br/>");
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
}
});
});
</script>
</head>
<body>
</body>
</html>