JSON data parsing exception
When doing JSON data today, the following error occurred, saying that it was an exception to parse
VM1584:1 Uncaught SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at Object.success (customer.js:170)
at j (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at x (jquery.min.js:4)
at XMLHttpRequest.<anonymous> (jquery.min.js:4)
The request function is as follows:
$.ajax({
url: "../../XXX.php",
data: {CustomerName: $("#CustomerName").val()},
dataType: "json",
type: "post",
success: function(data) {
var jsonData = JSON.parse(data);
alert(data[0].code);
alert(data[0].msg);
},
error: function() {
alert("error!");
},
});
It should be noted that when using jQuery to complete Ajax requests, there is a .
between Ajax
and $
. You can’t leave it out here. Parsing exception is because after the end of Ajax request, the JSON data transferred in the background has been automatically converted to object
type. Therefore, there is no need to use JSON. Parse
manual conversion here
Similar Posts:
- [Solved] JS Ajax uploads an error “uncaught type error: illegal invocation”
- [Solved] Jquery ajax “Uncaught TypeError: Illegal invocation”
- How to Solve Error: Unexpected token o in JSON at position 1
- Ajax “SyntaxError: missing ; before statement” [How to Solve]
- [Solved] Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse
- Convert to IE9 below $. Ajax to return “no transport” across domains
- [reprint] extjs sets the timeout of Ajax request
- Uncaught SyntaxError: Unexpected token o
- Uncaught typeerror: the solution of illegal invocation problem