用于非 JSON 输出的 drupal_json 的任何替代方案

发布于 2024-09-13 04:10:41 字数 225 浏览 1 评论 0原文

在 drupal 中的 AJAX 回调中,通常建议使用 drupal_json() 将数据发送到客户端。该函数将原始数据转换为 JSON 以及 HTML 编码。

我想将不经过编码的 HTML 数据发送给客户端。 为此,我使用以下代码:

print $html_output;
exit(0);

drupal 中是否有任何推荐或最佳方法可以做到这一点?

In an AJAX call back in drupal it is normally recommended to use drupal_json() to send data to client. This function converts the raw data into JSON along with HTML encoding.

I want to send the HTML data without encoding to client.
for this I am using following code:

print $html_output;
exit(0);

Is there any recommended or best way in drupal to do so?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七度光 2024-09-20 04:10:41

如果您只需要输出从菜单回调返回的 HTML 输出,那么以下代码是正确的:

print $html_output;
module_invoke_all('exit');
exit();

如果您希望输出与 Drupal 正常输出的块一起出现,则需要将代码更改为以下代码:

return $html_output;

If you need to output only the HTML output returned from the menu callback, then the following code is the correct one:

print $html_output;
module_invoke_all('exit');
exit();

If you want your output to appear together the blocks Drupal normally output, then the code needs to be changed to the following:

return $html_output;
一个人的夜不怕黑 2024-09-20 04:10:41

这样就可以了。尽管您应该首先调用 hook_exit 。然而,这在某种程度上简化了框架,它可能在简单的情况下工作,但不适用于表单等。

我唯一一次使用此方法是如果我打印一些已准备好 json 编码的数据。

That will do the trick. Allthough you should invoke hook_exit first. However this is shortcutting the framework some what, it may work in simple cases but wont work for forms etc.

The only time I have used this method is if I am printing some data which is allready json encoded.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文