Jquery getJson无法使用php json_encode

Jquery getJson not working with php json_encode

本文关键字:php json encode getJson Jquery      更新时间:2023-09-26

以下是示例php json_encode输出

{"user_id":34543456532,"user_status":true,"name":"ABC","propic":"http:'/'/pbs.twimg.com'/profile_images'/....."}

我正在使用余烬,所以路线是

  model: function(params) {
    return Em.RSVP.hash({
      uposts: tweets,
      ustat: [$.getJSON( "status.php")]
    });
  }

处理这个问题的HTML/Handerbars代码是

{{#if ustat.[0].user_status}}
do something
{{else}}
do something else
{{/if}}

然而,当我使用一些伪值(如)时,user_status总是返回false

  model: function(params) {
    return Em.RSVP.hash({
      uposts: tweets,
      ustat: [{"user_id":34543456532,"user_status":true,"name":"ABC","propic":"http:'/'/pbs.twimg.com'/profile_images'/....."}]
    });
  }

它运行良好,错误在哪里?我该如何修复它?感谢

$.getJSON不返回调用中的数据,而是返回promise。也许这样的东西会更好用:

$.getJSON( "status.php").then(function(statusData){
   ...
   model: function(params) {
    return Em.RSVP.hash({
      uposts: tweets,
      ustat: [statusData]
    });
   }
   ...
});