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.