我需要更新tinymce窗口中提交的變量。如何在提交Tinymce內容之前等待ajax數據
這裏TinyMCE的代碼:
tinymce.PluginManager.add('tc_button',function(editor,url){
editor.addButton('tc_button',{
title: 'Images',
onclick: function(){
editor.windowManager.open({
title: 'Images',
buttons: [{text: 'Add Shortcode', onclick: 'submit'}, {text: 'Cancel', onclick: 'close'}],
body: [
{type: 'container',
label : 'Image URL',
items: [
{type: 'textbox', id: 'image1', name : 'image1', style:'width:270px'},
{type: 'listbox', id: 'effect1', name: 'effect1', style:'margin-left:10px'},
]}
],
onsubmit: function(e) {
jQuery.post(ajax_url,
{
action: 'save_image',
image: imageData,
}
),
function (data){
var jsonData = tryParseJSON(data);
if (jsonData !== false) {
var new_url = jsonData.attachment_url;
jQuery('#image1').attr('src', new_url);
}
};
editor.insertContent('[shortcode image1="' + e.data.image1 + '"]');
}
});
}
});
});
我需要之前editor.insertContent
運行jQuery('#image1').attr('src', new_url)
Ajax調用內內編輯添加。我如何設置它,以便等待ajax調用結束並且#image1
源用ajax結果值更新?
在此先感謝。
你爲什麼不把'editor.insertContent(...)'回調裏面? –
我試過了,但'editor.insertContent'不起作用。沒有添加短代碼。 –