To process a web form asynchronously, jQuery is used to loop through all fields, and the .val()
of the field is saved into an array. This array is then sent to a PHP document which processes the data, by using an .ajax
call with dataType: 'json'
.
When a (text) field contains double quotes "
, 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?
I'd love to solve this problem and have tried some things, for instance:
field.val().replace(/"/g, '\"');
when saving into the array, but this stops the javascript from executing.
How can I solve this issue?