Problem with escape characters

Problem with escape characters

WavfactWavfact Posts: 12Questions: 0Answers: 0
edited December 2010 in General
I am trying out the server_side example but using my own data. I noticed in the example http://www.datatables.net/examples/server_side/server_side.html the server side php script is using a lot of mysql_real_escapes which breaks valid json data.. i have a name field in my table with the contents "Fisher's Auto care" , using mysql_real_escape changes the data to "Fisher\'s Auto care" so I had to do a string replacement in order to get valid json..

My biggest problem is the search feature, whenever I press a key it immediately gives me an alert messaging saying "DataTables warning JSON data from server could not be parsed. This is caused by a JSON formatting error."

Firebug says :The 'charCode' property of a keyup event should not be used. The value is meaningless.
Line 0

I am using the latest 1.7.5.. anyone run into this problem? The same sample on the web site runs fine..

Replies

  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin
    Could you show us the JSON you are getting from Firebug (or whatever) when you get this error in DataTables please? The mysql_real_escape_string() usage in the string input for the queries I believe is correct since you don't want to be passing in unesacped user input to the database. However, that doesn't directly effect the JSON output - that is at the end of the script. If you are using the script which comes with DataTables 1.7.5 (also available here: http://datatables.net/development/server-side/php_mysql ) then it uses json_encode() to make sure the string returned is valid.

    So yes, I think seeing the full string returned from the server would be useful.

    Allan
  • WavfactWavfact Posts: 12Questions: 0Answers: 0
    I was missing the json_encode, works fine now..

    Thanks!
This discussion has been closed.