The solution of unexpected syntax error: unexpected identifier
Analysis of the causes of the solutions to errors
Error phenomenon
As shown in the title, this error occurs when the foreground parses the JSON object passed in the background. Other code is very simple, as follows:
$.getJSON("Index_ToDoList", { type: "GetBacklog" }, function (data) {
var rowData = eval('(' + data + ')');
alert(rowData[0].RiskNumber);
}
})
Results no matter how to test and modify, always report the above error. Online Baidu also many times, are saying less or more a “comma”, but tested the background, JSON format is no problem.
resolvent
One hour later, when I couldn’t figure out the solution, I suddenly found that in other code, the parsing was done by another method. I quickly tested the code as follows:
$.ajax({
url: 'Index_ToDoList?random=' + Math.random(),
data: { "type": "GetBacklog" },
success: function (data) {
var rowData = eval('(' + data + ')');
alert(rowData[0].RiskNumber);
}
})
It’s OK! The data is also parsed out!
Cause analysis
The most likely reason is that there is a problem with the version of jQuery quoted in this framework, or some code has been changed by others (I don’t have the ability to look up the code), so this writing method is feasible in this framework. It can be seen that maintaining the code left behind by others is such a pitfall, but sometimes, if you can’t rewrite the code, you have to be more careful!
Read More:
- “Unexpected syntax error: unexpected identifier”.
- Syntax error: unexpected EOF while parsing
- Error: syntax error – unexpected token P in JSON at position 0
- Solve the problem of syntax error: unexpected end of file or syntax error near unexpected token ` fi ‘error
- Unexpected syntax error: unexpected token<
- Unexpected token o in JSON at p
- Error resolution of unexpected token in JSON at position 0
- SyntaxError: unexpected EOF while parsing
- Unexpected token u in JSON at position 0
- Parsing error: Unexpected token
- [system]SyntaxError: Unexpected token u in JSON at position 0
- syntax error near unexpected token `then’ problem solution
- JS error: unexpected token u in JSON at position 0
- Syntax error: unexpected token in uni app project compilation
- PHP reports “parse error: syntax error, unexpected T”_ The solution of “variable”
- Error: unexpected syntax error: unexpected token<
- Shell script syntax error near unexpected token ‘$’Do
- Vue の NPM run serve error: parsing error: unexpected token<
- Uncaught syntax error: unexpected token ‘< 0‘
- [Fixed] Syntax error: word unexpected (expecting “)”)