[英]Trying to save the contents of a contenteditable div to MySQL database
Alright, so I want to be able to submit the contents of a contenteditable div into a MySQL database. 好吧,所以我希望能够将contenteditable div的内容提交到MySQL数据库中。 I've got a (contenteditable='true') div populated with HTML code from a MySQL database.
我有一个(contenteditable ='true')div,其中填充了来自MySQL数据库的HTML代码。 It's something like this:
就像这样:
$page = $_GET['page'];
$getpage = mysql_query("SELECT * FROM pages WHERE title = '$page'") or die(mysql_query());
$row = mysql_fetch_assoc($getpage);
$pagecode = $row['pagecode'];
<div class="editable" contenteditable="true">
<?php echo $pagecode; ?>
</div>
And I want to control this with a regular link: 我想通过常规链接来控制它:
<a href="#" onclick="somefunction()">Save</a>
Maybe this could work with a hidden form that's controlled with Javascript, but I really have no clue. 也许这可以用Javascript控制的隐藏形式工作,但我真的不知道。
The goal is to have something like an HTML editor, which displays the HTML code from the database inside the editable div and allows the user to edit it and save it back in the database. 我们的目标是拥有类似HTML编辑器的功能,它可以在可编辑div中显示数据库中的HTML代码,并允许用户对其进行编辑并将其保存回数据库中。 Any help is greatly appreciated.
任何帮助是极大的赞赏。
Thanks, 谢谢,
Gill. 鳃。
In your AJAX code, make a new AJAX request to a processor. 在您的AJAX代码中,向处理器提出一个新的AJAX请求。 Assign an
id='id_name_here
to your div
and pass the id_name_here.innerHTML
to the url. 为您的
div
分配一个id='id_name_here
,然后将id_name_here.innerHTML
传递给该网址。 Then you can do something with it from your processor. 然后,您可以从处理器中对其进行处理。
// JS
function somefunction() {
var updated_div_info = document.getElementById('id_name_here').innerHTML;
// POST TO AJAX ...
}
// PHP
<?php
$updated_div_info = $_POST['updated_div_info'];
// INSERT THIS INTO THE DB
try this 尝试这个
function somefunction(){
var html = encodeURIComponent($(".editable").html());
$.ajax({
url: "save.php",
data: "content="+html
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.