Reputation: 49
I use jqgrid 4.13.1. In the jqfiddle example http://jsfiddle.net/9ezy09ep/162/, when I try to filter the list like this (important : replace %tab% with the tab char, ascii value=9):
Customer ID > Contains > %tab%HANAR
I get the error in the file jquery-1.12.0.min.js :
SyntaxError: JSON.parse: bad control character in string literal at line 1 column 67 of the JSON data
How to escape the tab char in the value field of the jqgrid filter ?
Upvotes: 1
Views: 211
Reputation: 221997
I analysed the problem. The problem exist because of usage xmlJsonClass.toJson
in the line of code of free jqGrid 4.13.1. The line come from old jqGrid (see here). I thought already to remove the usage of xmlJsonClass.toJson
and to use only JSON.stringify
, but I hold the usage of old methods hoping to hold better compatibility with old versions of jqGrid.
The problem is that JSON standard (see here) require to escape only "
and \
symbols and some other symbols, like tab, could be escaped:
The method xmlJsonClass.toJson
generates the string, which escapes tab (converts to two characters \t
) and JSON.stringify
don't do this.
The problem come later after one deserializes postData.filters
using $.parseJSON
, which calls JSON.parse
internally.
I made modification of the code of the Searching Dialog to use JSON.stringify
as the first choice (which exists in all modern web browsers and can be included in old web browsers by including json2.js). I will continue to use xmlJsonClass.toJson
for the fallback scenario only.
I committed the fix to GitHub, which fixes the problem. See http://jsfiddle.net/OlegKi/9ezy09ep/163/, which uses the latest sources from GitHub.
Upvotes: 2