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, for more information, see. 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:
/ hook for manipulating the form data before it is extracted;// convenient for use with rich editors like tinyMCE or FCKEditorvar 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:
// 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.