在我的项目中使用此MarkDown。 https://github.com/NextStepWebs/simplemde-markdown-editor
要使用Jquery Serialize获取表单im的值,问题是它不适用于MarkDown,使用简单的Textarea我的代码可以工作。
问题出在这里(这里有Markdown)。
<textarea id="messaggio" name="testo"></textarea>
加载降价的脚本
<script>
var simplemde = new SimpleMDE({ element: $("#messaggio")[0] });
</script>
JQUERY SERIALIZE
$("#invio").click(function(){
var dati = $("#form").serialize(); //recupera tutti i valori del form automaticamente
//form invio dati post ajax
alert(dati);
//invio
$.ajax({
type: "POST",
url: "/includes/inserisci.php",
data: dati,
dataType: "html",
success: function(msg)
{
alert("Chiamata inviata con successo");
},
error: function()
{
alert("Chiamata fallita, si prega di riprovare...");
}
});//ajax
});//bottone click
Inserisci.php
<?php
include('../core.php');
$titolo= urldecode($_POST['titolo']);
$post= urldecode($_POST['testo']);
$sql = mysql_query("")or die("Non riuscito");
mysql_close();
?>
FORM
<form id="form" class="form-horizontal shadow-z-1" action="#" method="post">
<fieldset>
<legend style="text-align: center; position: relative; top: 8px;">Inserisci un Post</legend>
<hr>
<div class="form-group">
<label for="inputTitle" class="col-lg-2 control-label">Titolo</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="inputText" name="titolo" placeholder="Scrivi qui il Titolo">
</div>
</div>
<div class="form-group">
<label for="textArea" class="col-lg-2 control-label" >Messaggio</label>
<div class="col-lg-10">
<textarea id="messaggio" name="testo"></textarea>
</div>
</div>
<div class="form-group is-empty is-fileinput">
<label for="inputFile" class="col-md-2 control-label">File</label>
<div class="col-md-10">
<input type="text" readonly="" class="form-control" placeholder="Browse..." pmbx_context="19E61A0C-3526-4E51-8535-935982C4C335">
<input type="file" id="inputFile" multiple="" pmbx_context="1D2BCAEA-08CC-476A-8F4A-EF6BD51B9102">
</div>
<span class="material-input"></span></div>
<div class="col-md-10 col-md-offset-2">
<button type="button" class="btn btn-default" onclick="document.getElementById('modalposta').style.display = 'none';">Cancel</button>
<button type="submit" class="btn btn-primary" id="invio" onClick="nascondiform();return false;">Submit</button>
<!--<button type="submit" class="btn btn-primary" onClick='send(); return false;' >Submit</button>-->
</div>
</fieldset>
</form>
答案 0 :(得分:0)
请查看文档:github.com/NextStepWebs/simplemde-markdown-editor您需要
simplemde.value()
Serialise仅适用于表单。您可以尝试在序列化之前将值复制回textarea:
$("#messagio").val(simplemde.value());
var dati = $("#form").serialize(); //recupera tutti i valori del form automaticamente
或
var dati = $("#form").serialize()+"&text="+JSON.stringify(simplemde.value());
可能
var dati = $("#form").serialize()+"&text="+encodeURIComponent(JSON.stringify(simplemde.value()));
答案 1 :(得分:0)
以这种方式工作。
var dati = $("#form").serialize()+"&text="+simplemde.value();
<强> PHP 强>
$post= urldecode($_POST['text']);