gpt4 book ai didi

jquery - PHP 和 JSON 注释帮助

转载 作者:行者123 更新时间:2023-12-01 01:11:46 24 4
gpt4 key购买 nike

感谢您的浏览

我的问题是我似乎无法让 jquery 显示我生成的数据。

这是我的 JSON 输出

("posts":[{"id":"1-2","time":"0","name":"dash","avatar":"http:\/\/www.gravatar.com\/avatar\/9ff30cc2646099e31a4ee4c0376091b0?s=182&d=identicon&r=PG","comment":"rtetretrete tet rt uh utert"},{"id":"2-2","time":"0","name":"james","avatar":"http:\/\/www.gravatar.com\/avatar\/d41d8cd98f00b204e9800998ecf8427e?s=182&d=identicon&r=PG","comment":"fsdfdfsdf\r\n"}])

这是我的 jquery

    $(document).ready(function(){
var url="comments.php";
$.getJSON(url,function(json){
$.each(json.posts,function(i,post){
$("#content").append(
'<div class="post">'+
'<h1>'+post.name+'</h1>'+
'<p>'+post.comment+'</p>'+
'<p>added: <em>'+post.time+'</em></p>'+
'<p>posted by: <strong>'+post.name+'</strong></p>'+
'<p>avatar: <strong>'+post.avatar+'</strong></p>'+
'</div>'
); });
});
});

最佳答案

我刚刚尝试使用 http://www.jsonlint.com/

验证您的 JSON

它失败了:

syntax error, unexpected TINVALID, expecting '{' or '[' at line 1
Parsing failed

整体(外部)括号需要从 () 更改为 {} 这将验证您的 JSON 并且脚本应该可以正常工作

关于jquery - PHP 和 JSON 注释帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3051644/

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