jQuery将值贴在Textarea不起作用,直到Ajax提交第二次
-
15-11-2019 - |
题
我有一个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:
- Form data is being collected
- beforeSubmit fires, and the collected form data is being passed as the first parameter
- 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;
};
不隶属于 StackOverflow