Solution for TinyMCE submitting AjaxForm to fail to obtain data

Source: Internet
Author: User

Solution for TinyMCE submitting AjaxForm to fail to obtain data

This article mainly introduces how TinyMCE submits AjaxForm to obtain data. The example analyzes the corresponding source code and corresponding solutions, which has some reference value. If you need it, you can refer

 

 

This article analyzes the solution for TinyMCE submitting AjaxForm to fail to obtain data. Share it with you for your reference. The specific analysis is as follows:

Before using AjaxForm, I made a Web form for small comments and used TinyMCE for text editing. To improve the user experience a little bit, we can use AjaxForm to implement Ajax submission. However, an accident occurred. That is, each submission. When the first submission is made, AjaxForm will not be able to obtain the content of the currently edited comment, that is, the content in TextArea. You need to click submit again to submit the content of TextArea.

The key is that the content on TinyMCE is not updated to TextArea before submission. So I want to see if AjaxForm has event binding before submission. I found that in the beforeSubmit event, the formData content has been filled. Although I can manually fill the content of the current TinyMCE here, but I always think it is a pretty solution.

To find out whether there are other ways to solve this problem, I checked the source code of AjaxForm and found that the author of AjaxForm has proposed a unified solution for this problem. The specific source code is as follows:

1. The js Code is as follows:

The Code is as follows:

// Hook for manipulating the form data before it is extracted;
// Convenient for use 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:

The Code is as follows:

// Bind form using 'ajaxform'
$ ('# CommentForm'). ajaxForm (options );
// Bind the form-pre-serialize event and save the data of tinyMCE to textarea before the form-serilaize event is triggered.
$ ('# CommentForm'). bind ('form-pre-serialize', function (event, form, options, veto ){
TinyMCE. triggerSave ();
});

 

I hope this article will help you design javascript programs.

Related Article

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.