我有一个jQuery JHTML WYSIWYG编辑器,我需要手动将其输出追加到TextArea。表格通过AJAX提交。调用UpdateText函数才能抓住WysiWyg Div中的内容,并将其放在Textarea中以使AJAX发送它。我正在使用ajaxform“beforesubmit”回调来解雇此功能。

//For Ajax Form
$('#addFaci').ajaxForm({
        beforeSubmit: updateText,
        success: function(response) {
            eval(response);
        }
});

function updateText(formData, jqForm, options){
    var save = '#detail';
    $(save).val($(save).htmlarea("toHtmlString"));
    return true;
}; 
.

这不起第一个提交...您必须在UpdateText实际触发之前单击两次提交。有没有人有任何想法?

谢谢,

有帮助吗?

解决方案

When you hit submit this is what happens:

  1. Form data is being collected
  2. beforeSubmit fires, and the collected form data is being passed as the first parameter
  3. You're changing the value of textarea, but it's too late, because data has been already collected

Instead of changing textarea's value you should modify formData object.

UPD. Try this:

for (var i in formData) {
  if (formData[i].name == '...name of your textarea here...') {
    formData[i].value = ...wysiwyg's html...
  }    
}

Even easier, remove the hidden textarea and use this:

function updateText(formData, jqForm, options) {
    formData.push({name: 'textarea_name', value: .... })
    return true;
}; 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top