jquery - 通过 ajax POST 提交 nicEdit 文本编辑器的值不起作用

标签 jquery ajax forms submit nicedit

我找到了一些“解决方案”,但似乎没有一个对我有用。我正在使用 malsup 的 jquery 表单插件通过 POST 提交表单数据。表单元素之一是 nicEdit 框。这是我的代码:

html:

<div class="leftaligned">   
<h1>Add News:</h1>
<form enctype="multipart/form-data" id="addnewsform" action="addnewscode.php" method="POST">
<input type="hidden" name="isnewnews" value=1 />
<div class="missinginfo">
Please add a title and some content!
</div>
<h2>Title:</h2>
<input type="text" size="50" id="newtitle" name="newtitle">
<h2>Content:</h2>
<textarea style="width:590px; height:300px;" id="newcontent" name="newcontent"></textarea>
<br>
<div id="contentbuttons">
<input type="submit" value="Add News" class="submitnews" style="float:left;" /></form>
<input type="button" value="Cancel" onclick='parent.$.colorbox.close(); return false;'/>
</div>

这是单击提交按钮时当前调用的内容:

<script>
$(document).ready(function() { 
var options = {

    beforeSubmit: function(arr, $form, options) {
        var title = document.getElementById("newtitle").value;
        var content = document.getElementById("newcontent").value;
        alert(content);
        var title = document.getElementById("newtitle").value;
        if(title == "" || content == "") {
            parent.$.fn.colorbox.resize({height:635});
            $(".missinginfo").show();
            setTimeout(function()     {$(".missinginfo").hide();parent.$.fn.colorbox.resize({height:610});},2000);
            return false;
        }

    },

    success:       showResponse  
}; 

$('#addnewsform').submit(function() { 
    $(this).ajaxSubmit(options); 

    return false; 
});

function showResponse(responseText, statusText, xhr, $form)  { 
    parent.onAddNewsSuccess();
}  
});
</script>

我的#newcontent 文本区域是一个 nicEdit 框。

警报(内容)没有显示任何内容,所以我知道我还需要做一些其他事情才能提交 nicEdit 框中的文本。我错过了什么?

最佳答案

(在问题编辑中回答。转换为社区 wiki 答案。请参阅 What is the appropriate action when the answer to a question is added to the question itself? )

OP 写道:

Nevermind, I solved it using:

    beforeSerialize: function($form, options) {
    nicEditors.findEditor('newcontent').saveContent();
},

关于jquery - 通过 ajax POST 提交 nicEdit 文本编辑器的值不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11641255/

相关文章:

JavaScript异步设计书?

asp.net - 在 ASP.NET 中使用 jQuery

javascript - 从 Javascript 调用 perl 文件/函数和函数来更新 HTML

ruby-on-rails - 用于自定义操作的 Rails 表单

javascript - 编辑选项仅对在 php 中上传的用户可见

div 上的 Jquery 自定义动画

java - 当表单操作使用 Apache Shiro 转到 jsp 页面时,onClick 不起作用

javascript - 使用 jQuery DataTable 的未定义值

forms - 将MailChimp订户添加到具有注册表单而不是API的组中

javascript - 在选项卡模块上首次触发后 SlideUp 未触发