我想让我的代码发布HTML表单值。它有效,但我不能让它发布单引号' 。我认为这是由于序列化的使用。我到目前为止改为将单引号更改为2个单引号,但它没有用。
Javascript
$( "#verstuur-bericht" ).click(function() {
var nummeroftekensbericht=$.trim($("#message").val());
if(nummeroftekensbericht.length>0)
{
$.post('http://192.168.178.24/server/submit.php', $('#bericht-verstuur-form')).serialize()
$('#message').val('');
setTimeout(function(){
$("html, body").animate({ scrollTop: $(document).height()+40 }, 10);
}, 1200);
}
else {
Materialize.toast('Error: bericht is leeg!', 4000) // 4000 is the duration of the toast
}
});
Html
form id="bericht-verstuur-form" action="http://192.168.178.24/server/submit.php" 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>
</form>
答案 0 :(得分:0)
添加.replace(/\'/g,'\\\'');
来序列化解决了问题!
$ .post('https://--',$('#bericht-verstuur-form')。serialize()。replace(/ \'/ g,'\\''))