关于火狐执行var obj = eval(‘(‘ + data + ‘)‘);时 报SyntaxError: missing ] after element list错误,Chrome和IE正常
情形如下:
当使用ajax接收从后台传递过来的json数据时
$.ajax( {
type : "POST",
dataType : "json",
url : "RegisterAction.action",
data : params,
success : function(data) {
console.log(data);
var obj = eval(‘(‘ + data + ‘)‘);
console.info(obj);
},
error : function(data, status, e) {
alert("错误");
}
});当设置dataType : "json", 程序会跳到error中当去掉dataType : "json", 程序报SyntaxError: missing ] after element list错误
Struts配置为:
<struts> <package name="build" extends="json-default"> <action name="RegisterAction" method="register" class="com.home.RegisterAction"> <result type="json"></result> </action> </package> </struts>
public String register() {
PrintWriter out;
try {
out = response.getWriter();
out.print("{msg:true,name:‘" + name + "‘,sex:‘" + sex + "‘}");
out.close();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}解决以上关于火狐报错问题的方法为:将dataType设置为html或text即可也有可能因其他问题所产生,固本例不一定具有公共性,还需具体问题具体分析。
作者:itmyhome
出处:http://blog.csdn.net/itmyhome1990/article/details/41977941
欢迎加入JAVA技术交流群:74955800
SyntaxError: missing ] after element list 火狐问题
原文地址:http://blog.csdn.net/itmyhome1990/article/details/41977941