Datatable problem with backslash in server data processing
Datatable problem with backslash in server data processing
jwest
Posts: 8Questions: 4Answers: 0
I am using server processing with datatables.
This is my ajax returning data.
I found an error when I have a backslash in the string :
{"DT_RowId":"4427","pront":"4427","nome":"JOHN DOE","conv":"PETROBRAS\ DISTR ( R)","cpf":"","email":""}
See:"PETROBRAS\"
In this case, I found that backslash was the cause of the problem.
I know I can solve this particular problem, but the table database I am using has many rows, and may be, can have others chars that can cause problems to JavaScript in my page
Is there some settings in datatable to avoid it?
This discussion has been closed.
Answers
The error is: SyntaxError: Unexpected token in JSON at position 1017
at JSON.parse (<anonymous>)
at n.parseJSON (jquery.min.js:4)
at Xb (jquery.min.js:4)
at y (jquery.min.js:4)
at XMLHttpRequest.c (jquery.min.js:4)
Not really as it isn't a DataTables issue. The JSON isn't valid and its jQuery's JSON parser that is throwing the error.
Try running your string through JSONLink and you will see it stating that it is not valid JSON.
You need to escape the backslash to make it valid JSON.
Allan