【问题标题】:JSON TinyMCE return value "\t"JSON TinyMCE 返回值“\t”
【发布时间】:2013-03-13 23:05:47
【问题描述】:

我应该为“streszczenie”使用另一个变量吗?或者我该怎么办?

在我看来,TinyMCE 正文有 html,但我只得到 "\t" 可能我对 JS 有问题

this is new problem - this question is related with this link. I added this for other users

这是我在 TinyMCE 中编写的

这是我从 TinyMCE textarea "streszczenie" 得到的

如您所见,有文字 ghhfgh 但我无法获取此文字

现在我遇到了执行 JSON 的问题

<script type="text/javascript">

    function Save() {
        tinyMCE.triggerSave();
        var Temat_controll = $('#Temat').val();
        var Streszczenie_controll = tinyMCE.get('Streszczenie').getContent();
        var PelnyOpis_controll = $('#PelnyOpis').text();

            $.ajax({
                url: '@Url.Action("DodajTematSave", "StronaGlowna")',
                dataType: "json",
                data: { 
                    Temat: Temat_controll,
                    Streszczenie: Streszczenie_controll,
                    PelnyOpis: PelnyOpis_controll
                },
                type: "POST",
                async: false,
                error: function() {
                },
                success: function(data) {
                    if (data.Success) {
                        alert('success');
                    }

                }
            });
        }

</script>

我明白了,但 JSON 一直没有执行

当我单击按钮 tinyMCE.get('Streszczenie').getContent() 为空时,我检查了这个,但我不知道为什么,因为我已将文本放入 textarea

<script type="text/javascript">

    function Save() {
        var Temat_controll = $('#Temat').val();
        var $d = tinyMCE.get('Streszczenie').getContent();
        if ($d.length != 0) {
            if ($d.val().length != 0) {
                var Streszczenie_controll = tinyMCE.get('Streszczenie').getContent();
            }
            else {
                var Streszczenie_controll = 'ewewe';
            }
        }
        var PelnyOpis_controll = $('#PelnyOpis').text();

        $.ajax({
            url: '@Url.Action("DodajTematSave", "StronaGlowna")',
            dataType: "json",
            data: {
                Temat: Temat_controll,
                Streszczenie: Streszczenie_controll,
                PelnyOpis: PelnyOpis_controll
            },
            type: "POST",
            async: false,
            error: function () {
            },
            success: function (data) {
                if (data.Success) {
                    alert('success');
                }

            }
        });
    }

</script>

【问题讨论】:

标签: c# javascript asp.net-mvc json tinymce


【解决方案1】:

您以错误的方式获取内容,而不是通过 jQuery 的 val()

要获取 tinymce 内容,只需使用 tinyMCE 对象引用:

// Get the HTML contents of the currently active editor
console.debug(tinyMCE.activeEditor.getContent());

// Get the raw contents of the currently active editor
tinyMCE.activeEditor.getContent({format : 'raw'});

// Get content of a specific editor:
tinyMCE.get('content id').getContent()

如前所述: http://www.tinymce.com/wiki.php/API3:method.tinymce.Editor.getContent

希望它有所帮助。波兰人:)

【讨论】:

  • 你能看看我的 JSON 脚本吗?我写了这个 var Streszczenie_controll = tinyMCE.get('#Streszczenie').getContent();但现在我遇到了执行 JSON 的问题
  • 伙计,您通过get() 方法选择了错误的元素。它的工作原理类似于getElementById() 语法,因此您不能在开始时使用#(请仔细阅读文档tinymce.com/wiki.php/API3:method.tinymce.get)。或者只使用tinyMCE.activeEditor 而不是tinyMCE.get()
  • 尝试通过console.log(Streszczenie_controll)alert(Streszczenie_controll) 进行调试。 id 有您将 TinyMCE 应用到的 textarea 吗? id 属性应作为参数传递给get() 函数。尝试使用tinyMCE.activeEditor
  • 正如你在编辑我的帖子中看到的,这个工作 tinyMCE.get('Streszczenie').getContent() 但我可以t send this information to JSON probably I should write something like this tinyMCE.get('Streszczenie').getContent().toString() but I dont 知道如何。
  • 没有。函数getContent() 返回字符串。你读过文档吗?那是调试结果?
猜你喜欢
  • 1970-01-01
  • 2013-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-15
  • 1970-01-01
  • 2023-03-07
  • 2010-10-17
相关资源
最近更新 更多