Ajax Submit nicEdit

爷,独闯天下 提交于 2019-12-24 13:52:46

问题


I'm using nicEditor on one of my projects and i want to submit the content using jQuery from plugin. Here is my code

<script type="text/javascript">
bkLib.onDomLoaded(function() {
new nicEditor().panelInstance('txt1');
});
</script>


<script>
$(document).ready(function()
{
    $('#submit-from').on('submit', function(e)
    {
        e.preventDefault();
        $('#submit').attr('disabled', ''); // disable upload button
        //show uploading message

        $(this).ajaxSubmit({
        target: '#output-login',
        success:  afterSuccess //call function after success
        });
    });
});

function afterSuccess()
{
    $('#submit-from').resetForm();  // reset form
    $('#submit').removeAttr('disabled'); //enable submit button
    $('#loadding').html('');
}
</script>


<form id="submit-from" action="submit.php" method="post">

<input type="text" id="title" name="title" />

<textarea id="txt1" name="txt1" ></textarea>

<input type="submit" id="submit" value="Submit"/></div>

</form>

I'm using

jQuery from plugin: http://malsup.com/jquery/form/

nicEdit: http://nicedit.com/

All work fine except what ever in the nicEdit doesn't seems to be posting. If i remove the nicEdit text area will post fine. Can someone point me out the problem. Really appropriate your help.


回答1:


Try this:

// Get values from NICEditors
$('textarea').each(function () {
    var id_nic = $(this).attr('id');
    var nic = nicEditors.findEditor(id_nic);
    if (nic) nic.saveContent();
});             



回答2:


I think you should encode the HTML of the contenteditable div of nicEdit and then pass that value to the textarea when you try to submit the form.

$(document).ready(function()
{
    $('#submit-from').on('submit', function(e)
    {
        e.preventDefault();
        $('#submit').attr('disabled', ''); // disable upload button
        //show uploading message


        var encodedHTML = String($('.nicEdit-main').html())
                .replace(/&/g, '&amp;')
                .replace(/"/g, '&quot;')
                .replace(/'/g, '&#39;')
                .replace(/</g, '&lt;')
                .replace(/>/g, '&gt;');

        $('#txt1').val(encodedHTML);

        $(this).ajaxSubmit({
            target: '#output-login',
            success:  afterSuccess //call function after success
        });
    });
});


来源:https://stackoverflow.com/questions/22370993/ajax-submit-nicedit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!