TINYMCE commits ajaxform get no data solution _javascript tips

Source: Internet
Author: User

An example of this article is to analyze the solution of TINYMCE commit ajaxform get no data. Share to everyone for your reference. The specific analysis is as follows:

Before using Ajaxform, I made a small comment submitted by the Web form, commenting on the content using TINYMCE do text editing. In order to add a little user experience, it is convenient to take ajaxform to implement AJAX submission. But there was an unexpected incident. Is each submission, the first submission, Ajaxform will not be able to get the current editorial content, that is, textarea inside the content, to click again to submit, to textarea content to submit up.

The key is that the content on the TINYMCE is not updated to textarea before committing. So I want to see if Ajaxform has the event binding before the commit, found in the Beforesubmit event, formdata content has been filled, although this place can be the current TINYMCE content to fill up, but always feel is not very beautiful solution.

In order to find out if there are other ways to solve this problem, I looked at the source code of Ajaxform, found that the original Ajaxform author has proposed a unified solution for this problem, the specific source code is as follows:

1. JS code is as follows:

Copy Code code as follows:
Hook for manipulating the form data before it is extracted;
Convenient with rich editors like TINYMCE or FCKEditor
var veto = {};
This.trigger (' form-pre-serialize ', [This, options, veto]);
if (Veto.veto) {
Log (' Ajaxsubmit:submit vetoed via form-pre-serialize Trigger ');
return this;
}

2. The corresponding FCKeditor is similar:
Copy Code code as follows:
Bind form using ' Ajaxform '
$ (' #commentForm '). Ajaxform (options);
Bind the Form-pre-serialize event to save the TINYMCE data to textarea before triggering the Form-serilaize event
$ (' #commentForm '). Bind (' Form-pre-serialize ', function (event, form, options, veto) {
Tinymce.triggersave ();
});

I hope this article will help you with your JavaScript programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.