Advertisement
EarthmanWeb

workaround

Feb 3rd, 2014
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3.             var someJSON = '<?php
  4.  
  5. //php to escape the apostrophe's since people use them all teh time
  6.  
  7.             $retrack_jsondata = addcslashes($retrack_jsondata,'\'');
  8.             echo $retrack_jsondata; ?>';
  9.  
  10.     <script type="text/javascript">
  11.         jQuery(document).ready(function($){
  12.  
  13. // front-end js to disallow user input of characters that break the JSON when it is trying to be parsed:
  14.  
  15.             $('#journal-entry').keypress(function(e) {
  16.                 // Check if the value of the input is valid
  17.                 console.log(e.keyCode );
  18.                 var valid
  19.                 switch(e.keyCode){
  20.                     case 34 : // "
  21.                     case 91 : // [
  22.                     case 92 : // \
  23.                     case 93 : // ]
  24.                     case 123 : // {
  25.                     case 124 : // |
  26.                     case 125 : // }
  27.                             valid = false;
  28.                     break;
  29.                     default:
  30.                             valid = true;
  31.                     break;
  32.                 }
  33.                 if (!valid)
  34.                     e.preventDefault();
  35.             });
  36.         });
  37.     </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement