gpt4 book ai didi

ajax - Drupal 7 ajax_command_* 创建不需要的 div

转载 作者:行者123 更新时间:2023-12-04 23:10:09 24 4
gpt4 key购买 nike

我在 Drupal 7 中使用 AJAX 回调填充一个选择框。我已经尝试了 ajax_command_append() 和 ajax_command_html() 来设置新的 <option...>语句,但它们都将我创建的 HTML 包装在 <div> 中.这会导致 <select>不显示任何选项。

有没有办法告诉 Drupal “嘿,笨蛋,这正是我想要的 HTML,别惹它”?

我可以编写一些 jQuery 代码来删除我猜的 div,但如果我能阻止它首先被添加,那会好得多。

最佳答案

是的你可以!

声明您自己的自定义 js 回调。在下面的示例中,我使用了跨度而不是 div。但是您显然可以完全删除包装器。

PHP:

function my_ajax_callback() {
$data = 'saved!';
// instead of using ajax_command_html, we provide our own
// js custom callback function
$output = array(
'#type' => 'ajax',
'#commands' => array(
array('command' => 'myjscallback', 'data' => $data),
),
);

return $output;
}

JS:
$(function() {
Drupal.ajax.prototype.commands.myjscallback = function (ajax, response, status) {
$('#save-btn-message').html('<span>' + response.data + '</span>');
};
});

关于ajax - Drupal 7 ajax_command_* 创建不需要的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9607393/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com