通过ajax POST提交nicEdit文本编辑器的值,不起作用
I've found a few "solutions" but nothing seems to work for me. I'm using malsup's jquery form plugin to submit form data via POST. One of the form elements is a nicEdit box. Here's my code:
我找到了一些“解决方案”,但似乎没有什么对我有用。我正在使用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>
and here's what's currently called when the submit button is clicked:
这是当点击提交按钮时当前调用的内容:
<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>
My #newcontent text area is a nicEdit box.
我的#newcontent文本区域是一个nicEdit框。
The alert(content) displays nothing, so I know there's something else I need to do to get the text inside the nicEdit box to submit. What am I missing?
警报(内容)什么都没有显示,所以我知道我需要做一些其他事情来获取提交的nicEdit框内的文本。我错过了什么?
1 个解决方案
#1
0
(Answered in a question edit. Converted to a community wiki answer. See What is the appropriate action when the answer to a question is added to the question itself? )
(在问题编辑中回答。转换为社区维基答案。请参阅问题答案添加到问题本身时,适当的操作是什么?)
The OP wrote:
OP写道:
Nevermind, I solved it using:
没关系,我用以下方法解决了它:
beforeSerialize: function($form, options) { nicEditors.findEditor('newcontent').saveContent(); },
更多相关文章
- Ajax php登录表单不指向另一个页面
- 分享27款非常棒的 jQuery 表单插件
- 解析PHP的基本文本输出
- 在体html中搜索文本的最佳方法是什么?
- 使用jquery animate()实现对文本的反弹效果?
- Jquery禁用/启用按钮与文本框代码
- 获取复选框的文本属性
- 用jQuery编写网页-表单检查
- jQuery中的bind绑定事件与文本框改变事件的临时解决方法