jquery:$.post("url", {
parentId : provinceValue
}, function(data) {
alert('123456');
}, "json");struts2 action:
try {
out = getResponse().getWriter();
JSONArray json = JSONArray.fromObject(list);//list非空
out.print(json.toString());
out.flush();
out.close();
}
并没有用strust2的json插件,直接使用json的jar问题:没有执行回调函数。还不报错! 可能是什么原因?
parentId : provinceValue
}, function(data) {
alert('123456');
}, "json");struts2 action:
try {
out = getResponse().getWriter();
JSONArray json = JSONArray.fromObject(list);//list非空
out.print(json.toString());
out.flush();
out.close();
}
并没有用strust2的json插件,直接使用json的jar问题:没有执行回调函数。还不报错! 可能是什么原因?
解决方案 »
- struts2 <s:select>问题
- 谁来帮我解决下这个正则表达式的问题?谢谢了
- java操作word文档
- 关于hibernate的查询问题,在线请教高手来解答
- struts2上传文件遇到难题
- 1到99的数字,不限制加数的情况下,有多少可能它们的和等于100,如:1+99=100, 1+2+97=100
- struts上传文件 文件空指针,控制台没报错。。
- win2003+iis6+tomcat5+jk2配置出错
- tomcat与resin比较一下 哪个好
- 请教使用eclipse开发EJB的问题??
- 使用hibernate update colb字段出现问题
- WebLogic Server 控制台登录问题
在这句后面在加一句 out.print(true);
response.setContentType("application/json;;charset=UTF-8");编码按照你的来
public static void renderJson(final String string, final String... headers) {
render("application/json", string, headers);
}
/**
* 直接输出内容的简便函数.
* eg.
* render("text/plain", "hello", "encoding:GBK");
* render("text/plain", "hello", "no-cache:false");
* render("text/plain", "hello", "encoding:GBK", "no-cache:false");
*
* @param headers 可变的header数组,目前接受的值为"encoding:"或"no-cache:",默认值分别为UTF-8和true.
*/
public static void render(final String contentType, final String content, final String... headers) {
try {
//分析headers参数
String encoding = "UTF-8";
boolean noCache = true;
for (String header : headers) {
String headerName = StringUtils.substringBefore(header, ":");
String headerValue = StringUtils.substringAfter(header, ":"); if (StringUtils.equalsIgnoreCase(headerName, ENCODING_PREFIX)) {
encoding = headerValue;
} else if (StringUtils.equalsIgnoreCase(headerName, NOCACHE_PREFIX)) {
noCache = Boolean.parseBoolean(headerValue);
} else
throw new IllegalArgumentException(headerName + "不是一个合法的header类型");
} HttpServletResponse response = ServletActionContext.getResponse(); //设置headers参数
String fullContentType = contentType + ";charset=" + encoding;
response.setContentType(fullContentType);
if (noCache) {
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
} response.getWriter().write(content); } catch (IOException e) {
logger.error(e.getMessage(), e);
}
}