Joran Dob Joran Dob - 4 months ago 15x
jQuery Question

Ajax post form serialise, post quotes '

I am trying to let my code post HTML form values. It works but i cannot get it to post single quotes ' . I think this is due the usage of serialise. i so far changed to on post change the single quote to 2 single quotes, but it didnt work.


$( "#verstuur-bericht" ).click(function() {
var nummeroftekensbericht=$.trim($("#message").val());
$.post('', $('#bericht-verstuur-form')).serialize()
$("html, body").animate({ scrollTop: $(document).height()+40 }, 10);
}, 1200);
else {
Materialize.toast('Error: bericht is leeg!', 4000) // 4000 is the duration of the toast




form id="bericht-verstuur-form" action="" method="post">
<input style="display:none;" type="text" name="idu" value="<?php echo $_SESSION['user_id']; ?>" id="user_id"/>
<input style="display:none;" type="text" name="nameu" value="<?php echo $_SESSION['user_full_name']; ?>" id="naam" placeholder="Enter name" />
<input style="display:none;" type="number" name="user_level" value="3" id="user_level"/>

<input placeholder="Typ hier!" style="width: calc(98% - 116px); color:#000; margin-left:15px;" name="message" id="message" type="text" class="validate input-chat-style">

<ul id="nav-mobile" class="right ">

<a style="color:#444444; font-weight: bold; background-color:transparent; " id="verstuur-bericht">VERSTUUR</a>


Adding .replace(/\'/g,'\\\''); to serialize solved the problem! $.post('https://--', $('#bericht-verstuur-form').serialize().replace(/\'/g,'\\''))