如何通过ajax请求在froala编辑器中发送其他表单数据?

问题描述

我正在使用froala编辑器v2,并且我需要通过ajax请求保存表单内容,因此我尝试按照以下方式进行操作

HTML

<form enctype="multipart/form-data" id="composeForm" action="#" method="post">
     <input type="file" name="compose_attachments[]" id="file-7" class="inputfile theme-inputfile" accept=".jpg,.jpeg,.png,.xls,.xlsx,.csv,.pdf,.ppt,.doc,.docx" multiple />
<input type="text" class="form-control inputES" placeholder="Email Subject" name="compose_subject">
<input class="autoTags" type="text" value="" data-role="tagsinput" placeholder="" name="compose_to">
<input class="autoTags" type="text" value="" data-role="tagsinput" placeholder="" name="compose_cc">
<input class="autoTags" type="text" value="" data-role="tagsinput" placeholder="" name="compose_bcc">
<textarea class="froala-editor-mail" id="composeEmailBody" name="compose_body"></textarea>
<button type="button" class="btn btn-green-bs p-lr-30 mr-10" id="SendComposedEmail">SEND</button>
</form>

JS

<script>
var editor_compose = new FroalaEditor('#composeEmailBody',{
      // Set the save URL.
      saveURL: `${ajaxUrl}?method=sendTestemail`,// HTTP request type.
      saveMethod: 'POST',saveParams: new FormData($("#composeForm")[0]),events: {
                    'save.before': function () {
                        // Before save request is made.
                        showLoader(0);
                    },'save.after': function () {
                        // After successfully save request.
                        showLoader(1);
                    },'save.error': function () {
                        // Do something here.
                        alert("Save error;");
                    }
      }
});
document.querySelector('#SendComposedEmail').addEventListener("click",function () {
      editor_compose.save.save();
});
</script>

PHP

<?PHP 
case 'sendTestemail':
        echo "<pre>";print_r($_POST);print_r($_FILES);exit;
    break;
?>

输出

Array
    (
    )

$ _ POST和$ _FILES为空,仅由编辑器HTML值获取

因此,我无法在ajax请求中获取formData。如何解决

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)