我写了个火狐调用ajax返回json的方法,每次都是在执行到代码var json = eval("("+data+")");的是时候抛出如下的错误,但是在ie下正常
POST http://127.0.0.1:8080/sshtest/test/testAjax.action
200 OK
7ms
jquery-1.8.3.js (第 8434 行)
头信息Post响应XMLCookies[{"id":"1","name":"name1"}]SyntaxError: missing ] after element list
([object XMLDocument])
页面脚本代码如下$.ajax({
type : "POST",
//dataType : "json",
url : "testAjax.action",
data : {
'users.id' : 49
},
success : function(data) {
var json = eval("("+data+")");
}
});
后台action代码如下@Action(value = "/testAjax")
public void testAjax() throws Exception {
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
Map<String, String> map = new HashMap<String, String>();
map.put("id", "1");
map.put("name", "name1");
list.add(map); JSONArray jsonArray = JSONArray.fromObject(list); //response.setContentType("application/json;charset=UTF-8");
//response.setCharacterEncoding("UTF-8");
response.getWriter().print(jsonArray.toString());
}
POST http://127.0.0.1:8080/sshtest/test/testAjax.action
200 OK
7ms
jquery-1.8.3.js (第 8434 行)
头信息Post响应XMLCookies[{"id":"1","name":"name1"}]SyntaxError: missing ] after element list
([object XMLDocument])
页面脚本代码如下$.ajax({
type : "POST",
//dataType : "json",
url : "testAjax.action",
data : {
'users.id' : 49
},
success : function(data) {
var json = eval("("+data+")");
}
});
后台action代码如下@Action(value = "/testAjax")
public void testAjax() throws Exception {
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
Map<String, String> map = new HashMap<String, String>();
map.put("id", "1");
map.put("name", "name1");
list.add(map); JSONArray jsonArray = JSONArray.fromObject(list); //response.setContentType("application/json;charset=UTF-8");
//response.setCharacterEncoding("UTF-8");
response.getWriter().print(jsonArray.toString());
}
解决方案 »
- 火狐不支持的种种....
- servlet 过滤器问题
- 100分求教:奇怪的异常
- 怎么捕捉到用户的浏览器退出?
- 如何在Servlet实现对文件的复制并转移操作?
- 开发类似下面的商务网站得多长时间?
- <jsp:useBean id="getMap" scope="page" class="java.util.HashMap">这里面的 <jsp:setProperty 应该怎么在HashMap里面put几个参数及值?
- 两个ServletClass怎么配置web.xml文件呢?
- flex中大数字从XML中取出转换成ArrayCollection时纯数字字符转换成数字
- 急!请问在jsp中有没有和asp中:response.end作用等效的语句!
- 有没有用过efs frame开源框架的进来聊聊
- 关于泛型。
使用 result = eval(" ("+data+") ");时报如下错误错误: SyntaxError: missing ] after element list 解决方案:不使用eval转,而直接使用data。原因:$.ajax( {
type : "post",
dataType : "json", //这里已经定义数据格式jquery调用时会检测到,从而直接把返回格式当做json处理,所以再转化会报错。