title: Escaping double quotes in Javascript / jQuery to send via POST as JSON to PHP
body: <p>To process a web form asynchronously, jQuery is used to loop through all fields, and the <code>.val()</code> of the field is saved into an array. This array is then sent to a PHP document which processes the data, by using an <code>.ajax</code> call with <code>dataType: 'json'</code>.</p>
  
  <p>When a (text) field contains double quotes <code>"</code>, the PHP receives only the part of the string up to the double quotes. The full string is available in the javascript, so something goes wrong with sending it as JSON over POST?</p>
  
  <p>I'd love to solve this problem and have tried some things, for instance:</p>
  
  <pre><code>field.val().replace(/"/g, '\"');
  </code></pre>
  
  <p>when saving into the array, but this stops the javascript from executing. </p>
  
  <p>How can I solve this issue?</p>