这个结果如何传递过去?

php -f /var/www/html/test-json.php

[ {title:"祝大家开心",
         content:"非常感谢大家长期以来的帮助",
        author:"唐三彩",
         email:"sanyo@tom.com",
        ip:"59.51.24.37"}
, {title:"到此一游",
         content:"<p><img alt="" src="upfiles/54591303758197437.jpg" /></p>
<p><img alt="" src="upfiles/20130714_121621_2779.jpg" /></p>
<p><img height="46" alt="" width="615" src="/php/8/example/8.1/fckeditor/editor/filemanager/connectors/php/upfiles/20130714_123447_8018.png" /></p>
<p>本人今天到此一游</p>",
        author:"小神马",
         email:"shemo@qq.com",
        ip:"201.11.43.45"}
, {title:"请教个问题",
         content:"虚拟目录中的文件如何浏览",
        author:"李博士",
         email:"tdkd@163.com",
        ip:"89.12.34.56"}
, {title:"祝大家开心",
         content:"非常感谢大家的帮助",
        author:"胡积分",
         email:"xta@tom.com",
        ip:"202.103.56.6"} 

现在,我希望用另外一个test-json.html调用这个test-json.php,并将结果输出。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    
<script src="http://127.0.0.1/jquery-3.3.1.min.js"></script>
<h2 align="center">Ajax显示数据</h2>
<table>
    <tbody id="disp">
        <th>标题</th>
        <th>内容</th>
        <th>作者</th>
        <th>邮件</th>
        <th>来自</th>
    </tbody>
</table>

<script> 
$(function(){
    $.getJSON("test-json.php", function(data) {
        $.each(data,function(i,item){
            var tr = "<tr><td>" + item.title + "</td>"    +
                        "<td>"  + item.content  + "</td>" +
                        "<td>"  + item.author  + "</td>"  +
                        "<td>"  + item.email  + "</td>"   +
                        "<td>"  + item.ip  + "</td></tr>"
            $("#disp").append(tr);
        });
    });
});
</script>

</body>
</html>

上面的test-json.html 没有报错,但是为何没有显示数据?
改了代码,加了 + 号,不是 linong 说的问题。

图片描述

阅读 1.4k
1 个回答

content:"<p><img alt="" src="upfiles/54591303758197437.jpg" /></p>

这个看上去有问题

clipboard.png

加号呢?

然后就插入成功了呀,你现在显示什么?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题