如何通过ajax提交时获取nicEdit表单的内容?

时间:2011-03-05 23:27:23

标签: jquery ajax nicedit

所以我想做的是使用jQuery的AJAX函数提交表单。我选择的路线是使用$('#form')。serialize();然后将其作为GET请求传递。它解决了所有花花公子,精细和花花公子,直到我添加编辑器NicEdit,我将在网站上使用。

我已经研究过这个问题,而且情况就是这样,一旦NicEdit接管一个文本区域,它就会将文本区域隐藏到用户,而是让她写入一个文本区域。然后,这些数据将被放回通过按下正常提交按钮触发的文本区域。

现在的问题是:我没有正常的提交按钮,因此不会触发将数据放回文本区域的事件。我尽力去<打击> 解决问题谷歌解决方案,但我发现的一切都毫无价值。

考虑到我的情况的基本设置:http://jsfiddle.net/MMzhS/1/ - 如何在alert()之前将NicEdit表单中的数据提供给文本区域;被称为?

7 个答案:

答案 0 :(得分:23)

var nicE = new nicEditors.findEditor('assignment');
question = nicE.getContent();

'assignment'是你的textarea id。

textarea内容保存在问题变量上,希望这会有所帮助

答案 1 :(得分:12)

以下由#jQuery的BinaryKitten提供的内容相同,但我认为有点清晰:http://jsfiddle.net/MMzhS/5/

答案 2 :(得分:3)

  1. 创建一个nicEdit实例

    MyApp.editor = new nicEditor()。panelInstance('texarea_id');

  2. 让用户输入内容到他们内心的内容! (双关语意外)

  3. 获取内容:

    var content = MyApp.editor.instanceById('textarea_id')。getContent();

  4. 使用content照常发布内容。

答案 3 :(得分:3)

var nicInstance = nicEditors.findEditor(&#39; options1&#39;);  var messageContent = nicInstance.getContent();

其中options1是textarea的id

答案 4 :(得分:0)

var data = $('#peter div').eq(90).text();

是数据的信息。另外,请使用$.post代替$.get提交表单;对互联网很好。

答案 5 :(得分:0)

document.getElementById("content").value = "<html><head><title></title><head><body>"+nicEditors.findEditor("this will be your id of your textarea").getContent()+"</body></head></html>";
var templateContent = document.getElementById("content").value;

答案 6 :(得分:0)

对于想知道如何在nicEdit中添加自定义组合框的人,这里是我的博客文章,显示带有动态值的自定义下拉列表

Link

通过编辑NiceEdit js文件,我们可以在NicEdit中添加自定义组合框

通过以下方式,我们可以向NicEdit添加下拉列表或组合框。您可以通过ajax调用从数据库获取下拉值并在NicEdit中显示它 首先在aspx页面上下载并实现NicEdit 下载NiceEdit js文件,您可以按照代码(http://nicedit.com/

启用它
 <div style="height: 700px; width: 70%; overflow: scroll">                <div id="sample"><script type="text/javascript" src="../scripts/nicEdit.js"></script><script src="../nicExample/nicExample.js"></script>
                    <script type="text/javascript">
                        bkLib.onDomLoaded(function () {
                            //  nicEditors.allTextAreas()
                            new nicEditor({ fullPanel: true }).panelInstance('area2');});</script>
                    <h4>NicEdit Textarea</h4><textarea name="area2" id="area2" style="width: 70%; height: 700px"> </textarea>
                    </div></div>

现在在文件末尾的niceEdit.js文件中添加getddlData()Ajax函数

// AJAX call
function getddlData() {
    var ajaxResponse;
    $.ajax({
        type: "POST",
        url: 'NicEdit.aspx/GetBookMarkData', // AJAX call to fecth dropdown data
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        cache: false,
        // Text file name
        success: function (response) {
            //    //alert(data.d);    // or do some other data processing
            //   //return data.d;
            ajaxResponse = response;
        }
    });
    return ajaxResponse.d;
}

//将代码隐藏(.cs文件)中的webMethod添加到fetech下拉值到nicedit

   [WebMethod]
        public static string GetBookMarkData()
        {
///Also you can get DB's data here
            ///  (2 responses dropdown values being filled :  'drop down Value', drop down Text)
            /// Need DB data in , seprated list  Formate:  @@Test@@,TestOne, TestOne,  @@Test2@@,Test2,Test2
            string sbookmarkData = "<<Test_Name>>,Test Name,<<Test_Add>>,Test Add,<<Test_Location>>,Test Location,<<Test_City>>,Test City,<<Test_Phone>>,Test Phone";
            return sbookmarkData;
        }

现在打开NicEdit js文件并复制(行号1552)或搜索以下行:

var nicEditorFontFormatSelect = nicEditorSelect.extend({

Copy complete function and create another one by changing names etc

var nicEditorInsertBookmark = nicEditorSelect.extend({
    /* By Pankaj Sharma : Not Needed Now  */
    sel: {
        '[[Location]]': "Test Name",
        pre: "Test Address",
        h6: "Test City",
        h5: "Test State",
        h4: "Test Zip",
        h3: "Test ABC",
        h2: "Test One",

    },
    init: function () {
        /* Pankaj Sharma */
        this.setDisplay("Insert Bookmark");
        var response = getddlData();
        var responseArr = response.split(",");
        var strings = [];
        //for (itm in this.sel) {         
        //  //  var A = itm.toUpperCase();
        //    //this.add(  A,  this.sel[itm]  )
        //   }

        for (i = 0; i < responseArr.length; i++) {
            strings.push([responseArr[i], responseArr[i + 1]]);
            i = i + 1;
        }
        for (var i in strings) {
            this.add(strings[i][0], strings[i][1]);
        }
        /* END HERE*/
    },
});

排队1230行或搜索以下行:

var nicSelectOptions = {     纽扣: { 在fontFormat函数下面添加以下内容

'CustomBookmark':{         name:__('Insert Bookmark'),         类型:'nicEditorInsertBookmark',//         命令:'InsertBookmark'// InsertBookmark     }

现在更新的功能应该如下所示

var nicSelectOptions = {
    buttons: {
        'fontSize': {
            name: __('Select Font Size'),
            type: 'nicEditorFontSizeSelect',
            command: 'fontsize'
        },
        'fontFamily': {
            name: __('Select Font Family'),
            type: 'nicEditorFontFamilySelect',
            command: 'fontname'
        },
        'fontFormat': {
            name: __('Select Font Format'),
            type: 'nicEditorFontFormatSelect',
            command: 'formatBlock'
        },
        'CustomBookmark': {
            name: __('Insert Bookmark'),
            type: 'nicEditorInsertBookmark',  //
            command: 'InsertBookmark'   //InsertBookmark
        }
    }
};

现在转到第1385行或     更新:功能(A){ 将其更改为

 update: function (A) {
        //  alert(this.options.command);
        if (this.options.command == 'InsertBookmark') {+
 var editor = nicEditors.findEditor("area2");
        var range = editor.getRng();
        var editorField = editor.selElm();

            editorField.nodeValue = editorField.nodeValue.substring(0, range.startOffset) + A + editorField.nodeValue.substring(range.endOffset, editorField.nodeValue.length);
}
        else {
            // alert(A);  
            /* END HERE */
            this.ne.nicCommand(this.options.command, A);
        }
        this.close()
    }

在DropDown选项上单击这将在光标位置的文本编辑器中添加下拉值。

结束,您应该能够看到结果