如何ajax提交从CKEditor输入的表单文本区域?

发布于 2024-09-10 05:06:45 字数 623 浏览 4 评论 0原文

我正在使用 CKEditor、jQuery 和 jQuery 表单插件,我想通过提交 CkEditor 表单的内容Ajax 查询。这是我的代码:

<form id="article-form" name="article-form" method="post" action="/myproject/save">
  <textarea name="bodyText" style="visibility: hidden; display: none;"></textarea>
  <script type="text/javascript">
    CKEDITOR.replace('bodyText');
  </script>

  <a onClick="$("#article-form").ajaxSubmit();">Submit</a>

</form>

不幸的是,Ajax请求似乎没有传递bodyText参数;

我做错了什么或者我怎样才能实现我所需要的?

谢谢。

I am using CKEditor, jQuery and jQuery form plugin and I would like to submit contents of the CkEditor form via an Ajax query. Here is my code:

<form id="article-form" name="article-form" method="post" action="/myproject/save">
  <textarea name="bodyText" style="visibility: hidden; display: none;"></textarea>
  <script type="text/javascript">
    CKEDITOR.replace('bodyText');
  </script>

  <a onClick="$("#article-form").ajaxSubmit();">Submit</a>

</form>

Unfortunately, it seems that the Ajax request does not pass the bodyText parameter;

What did I do wrong or how can I achieve what I need?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

转身泪倾城 2024-09-17 05:06:45

您需要首先调用以下命令,以使 CKEDITOR 更新其相关字段..

for ( instance in CKEDITOR.instances )
    CKEDITOR.instances[instance].updateElement();

所以

HTML

<a onClick="CKupdate();$('#article-form').ajaxSubmit();">Submit</a>

和 javascript

function CKupdate(){
    for ( instance in CKEDITOR.instances )
        CKEDITOR.instances[instance].updateElement();
}

you need to first call the following, to make the CKEDITORs update their related fields..

for ( instance in CKEDITOR.instances )
    CKEDITOR.instances[instance].updateElement();

so

HTML

<a onClick="CKupdate();$('#article-form').ajaxSubmit();">Submit</a>

and javascript

function CKupdate(){
    for ( instance in CKEDITOR.instances )
        CKEDITOR.instances[instance].updateElement();
}
烟燃烟灭 2024-09-17 05:06:45

这最适合我:beforeSerialize 回调

$('form#description').ajaxForm({
    beforeSerialize:function($Form, options){
        /* Before serialize */
        for ( instance in CKEDITOR.instances ) {
            CKEDITOR.instances[instance].updateElement();
        }
        return true; 
    },
    // other options
});

This works for me best: beforeSerialize callback

$('form#description').ajaxForm({
    beforeSerialize:function($Form, options){
        /* Before serialize */
        for ( instance in CKEDITOR.instances ) {
            CKEDITOR.instances[instance].updateElement();
        }
        return true; 
    },
    // other options
});
活雷疯 2024-09-17 05:06:45

如果您使用 jQuery 表单插件,则可以使用 beforeSubmit 选项以获得更优雅的解决方案:

$("#form").ajaxForm({
    beforeSubmit:  function()
{
        /* Before submit */
    for ( instance in CKEDITOR.instances )
    {
        CKEDITOR.instances[instance].updateElement();
    }
},

  // ... other options
});

If you use the jQuery form plugin, you can use the beforeSubmit option for a more elegant solution:

$("#form").ajaxForm({
    beforeSubmit:  function()
{
        /* Before submit */
    for ( instance in CKEDITOR.instances )
    {
        CKEDITOR.instances[instance].updateElement();
    }
},

  // ... other options
});
想你只要分分秒秒 2024-09-17 05:06:45

就我而言,以下内容对我有帮助,我只是在密封表格之前使用这两行。

  for ( instance in CKEDITOR.instances )
       CKEDITOR.instances[instance].updateElement();

  var data = $('#myForm').serializeArray();

In my case the following helped me,i just use these two lines before seializing the form.

  for ( instance in CKEDITOR.instances )
       CKEDITOR.instances[instance].updateElement();

  var data = $('#myForm').serializeArray();
幽蝶幻影 2024-09-17 05:06:45

我尝试了这样的事情:

首先我必须在 @Html.BeginForm 上放置一个 id = "#myForm" 之后,我将这些放在我使用脚本的脚本部分中:

<script type="text/javascript">
    $(document).ready(function CKupdate() {
        $('#myForm').ajaxForm(function () {
            for (instance in CKEDITOR.instances) {
                CKEDITOR.instances[instance].updateElement();
            }
        });       
    });
</script>

然后我为我做了类似的事情 =]提交按钮,它对我来说效果很好,不再按两次提交=]

<button type="submit" id="submitButton" onclick="CKupdate();$('#myForm').ajaxSubmit();">Submit</button>

I tried something like this:

First I had to put an id = "#myForm" on @Html.BeginForm afterwards, I put these in my scripts part where in I use the script:

<script type="text/javascript">
    $(document).ready(function CKupdate() {
        $('#myForm').ajaxForm(function () {
            for (instance in CKEDITOR.instances) {
                CKEDITOR.instances[instance].updateElement();
            }
        });       
    });
</script>

and then I did something like this =] for my submit button and it works fine for me, no more pressing the Submit twice =]

<button type="submit" id="submitButton" onclick="CKupdate();$('#myForm').ajaxSubmit();">Submit</button>
网名女生简单气质 2024-09-17 05:06:45

我只是这样做的:

$('#MyTextArea').closest('form').submit(CKupdate);

        function CKupdate() {
            for (instance in CKEDITOR.instances)
                CKEDITOR.instances[instance].updateElement();
            return true;
        }

I just did it like this:

$('#MyTextArea').closest('form').submit(CKupdate);

        function CKupdate() {
            for (instance in CKEDITOR.instances)
                CKEDITOR.instances[instance].updateElement();
            return true;
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文