简体   繁体   中英

PHP activity feed - similar to Facebook - How to convert response from json to HTML elements

We are building a activity stream kind of website very similar to facebook (in activity feed alone). For loading user's activity feed, we send the request to PHP file through AJAX method. Server file will handle the logic and return back the values as an array in JSON format. I wanted to know, is there any framework available to write the JSON response to HTML elements. Also, the fees are not similar. It will vary according to the type (Photo, Album, Status Updated, Shared, Liked, etc). So i need to load different template view for each of the activity feed. Actions will be common like Share, Comments for all feeds.

Can you please share which will be the best approach to load the content according to the data received. Also the content need to be refreshed periodically. I have pasted the sample JSON response below for reference:

{
  "id": "1",   
  "picture": "", 
  "link": "http://www.google.com", 
  "name": "Srini updated status", 
  "description": "Lorem ipsum",   
  "actions": [
    {
      "name": "Share", 
      "link": "http://networkedblogs.com/hGWk3?a=share"
    }
  ], 
  "type": "statusupdate",   
  "created_time": "2011-05-10T18:35:38+0000", 
  "updated_time": "2012-07-20T10:42:58+0000", 
  "likes": {    
    "count": 0
  }, 
  "comments": {
    "data": [
      {
        "id": "19292868552_10150189643478553_22286888", 
        "from": {
          "name": "Lorenzo Portillo", 
          "id": "613727863"
        }, 
        "message": "does anyone knows why i get a rhombus and '?' in my app     description when I publish in a user's wall, instead of a letter with accent?!?!?!?!?!?", 
        "created_time": "2012-05-28T13:48:45+0000"
      }, 
    "count": 1
  }
}

Need help / suggestions on how to design the template according to the json array in javascript. Any comments / code help will be more helpful.

Thanks in Advance,

Regards

Srinivasan.C

Well, if you consider making a very robust app, take a good look at emberjs .

You should also try jquery's (jquery mobile, jquery ui, jquery ajax )

You can create an html output in your php file when you are getting the response from the Facebook API. According to me you can do json operation easily in PHP. By using json_decode you get array and that you can traverse it and build an html as per your requirement.

Hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM