TinyMCE submits AjaxForm to obtain the data. tinymceajaxform
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:
Copy codeThe 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:
Copy codeThe 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.