[英]PHP removing everything after HTML tags
我有一個contenteditable div像這樣:
<form>
<div name="new_post" class="post" contenteditable="true"></div>
<button type="submit">Submit</button>
</form>
contenteditable div允許使用粗體和斜體標簽,但不允許其他標簽 。
我的問題是,如果用戶Hello there <u>world</u>!
類似Hello there <u>world</u>!
,它將以Hello there
保存在數據庫中。 似乎刪除了標簽后的所有內容,但我不知道為什么。
我正在使用AJAX和PHP處理帖子,因此這里是其余的代碼。
阿賈克斯:
$(document).ready(function() {
$(document).on("submit", "form", function(event) {
event.preventDefault();
alert($('.post').html()); // added this to debug it. This prints "Hello there <u>world</u>!"
$.ajax({
url: 'php/post.php',
type: 'POST',
dataType: 'json',
data: $(this).serialize() + "&post_field=" + $('.post').html(),
success: function(data) {
alert(data.message);
}
});
});
});
PHP:
<?php
$post = $_POST["post_field"];
// query to insert post into database goes here
$array = array('message' => $post);
echo json_encode($array);
?>
請幫忙!
更改:
$('.post').html()
至:
encodeURIComponent($('.post').html())
HTML字符需要在URL參數中編碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.