【发布时间】:2019-04-12 17:16:48
【问题描述】:
我有 2 个来自 php 脚本的回显,它们作为 json 发送到 ajax 调用。这 2 个回声将在 2 个不同的 div 中输出。 对于这 2 个回声,我创建了一个如下所示的数组:
$result = [
"one" => "this is echo 1",
"two" => "this is echo 2"
];
echo json_encode($result);
我现在想要包含 2 个文件(这将是回声),而不是这些回声。母猪我能做到吗?
所以我想要的是这样的:
$result = [
"one" => include('success.php'),
"two" => include('renderfiles.php')
];
我该怎么做?
顺便说一下,这是我的 jquery ajax:
$.ajax({
url: "",
type: "post",
data: new FormData(this),
dataType: 'json',
contentType: 'application/json',
success: function(data) {
$('.echo').html(data.one); // content ofinclude success.php should come here
$('.table-content').html(data.two); // content of include renderfiles.php should come here
【问题讨论】:
-
你期望success.php包含什么?
-
在两个包含中都是带有 html 的 php 代码
-
您将收到包含的结果(0 或 1),而不是内容...如果您需要未解析的 PHP,请使用 file_get_contents,使用已解析的 html,使用 outputbueffering 截取直接输出。
标签: php json ajax include associative-array