SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON火狐
2017-08-25 16:45
561 查看
SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON火狐
//错误代码 function showGoodsType(){ $.ajax({ url:"/sysCode/getSysCodeByTypeCode", type:"post", data:{ codeValue:"GOODS_TYPE" }, success:function(data){ data=JSON.parse(data); $("#goods_type").combobox({ data:data, valueField:'codeName', textField:'codeName', editable:false }); } }); }
以上代码在谷歌中执行没有问题,可以顺利的展示出combobox以及传回来的值,但是在火狐中就会报错JSON.parse: unexpected character at line 1 column 2 of the JSON,通过控制台查看后台返回的值是docment,这个不是我想要的类型,我后台返回的明明是json的字符窜,为什么会出现这个状况呢?原来是在使用ajax时没有申明返回的类型,就是下面这串代码
dataType : "json"
将上面的代码加入上面的方法中,再次查看返回的类型,发现返回的Object类型的值,也不需要转JSON了,像下面这样写就可以正常显示combobox了
function showGoodsType(){ $.ajax({ url:"/sysCode/getSysCodeByTypeCode", type:"post", data:{ codeValue:"GOODS_TYPE" }, dataType : "json", success:function(data){ $("#goods_type").combobox({ data:data, valueField:'codeName', textField:'codeName', editable:false }); } }); }
总之要细心啊啊啊啊啊啊啊啊啊啊啊
相关文章推荐
- SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
- SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data情况在easyui 的datagrid
- SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
- js - SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data jquery-1.9.1.min.js:3:4315
- 关于SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data错误的解决
- 集成支付宝时:JSON.parse: unexpected character at line 1 column 1 of the JSON data
- 集成支付宝时:JSON.parse: unexpected character at line 1 column 1 of the JSON data
- SyntaxError: JSON.parse: bad control character in string literal at line 1 column 16 of the JSON data
- firefox报错 关于 JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
- 错误处理:com.google.gson.stream.MalformedJsonException: Unexpected value at line 1 column 15
- 错误处理:com.google.gson.stream.MalformedJsonException: Unexpected value at line 1 column 15
- json.loads(s) returns error message like this: ValueError: Invalid control character at: line 1 column 33 (char 33)
- org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: unknown encoding
- Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 4171 异常的解决方法
- 严重: Parse Fatal Error at line 2 column 243: 已经为元素 "web-app" 指定属性 "xmlns"。 org.xml.sax.SAXParseExcept
- Parse Fatal Error at line 1 column 7: The processing instruction target matching "[xX][mM][lL]" is not allowed.
- Parse Fatal Error at line 5 column 89: 已经为元素 "web-app" 指定属性 "xmlns"。
- 关于Uncaught SyntaxError- Unexpected token o in JSON at position 1,chrome持续报错的相关解析
- Uncaught (in promise) SyntaxError: Unexpected token o in JSON at position 1
- Gson解析Json字符串出现异常:Expected a BEGIN_ARRAY but was STRING at line 1 column 107 $的解决方法