jQueryがTextAreaへの価値を付加してAjaxが2回目に提出されるまで機能しない
-
15-11-2019 - |
質問
jQuery JHTML WysiWYGエディタをフォームにしており、その出力を手動でテキストエリアに追加する必要があります。フォームはAjaxで送信されています。UpdateText関数は、Wysiwyg divにあるものをつかみ、テキストエリアに配置して、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が実際に起動する前に2回送信を2回クリックする必要があります。誰かがアイデアを持っていますか?
ありがとう、
解決
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