Symfony 2 + ajax Twitter-like uploads more content

I am creating a page where I can upload more “news” on the main page. Now there are 4 "news", and when I click the Load More button, it should load 4 new news.

I know how to do this with simple php and ajax. But I do not know how to do this with Symfony 2.

Using this site, sample code as a source, http://www.9lessons.info/2009/12/twitter-style-load-more-results-with.html

Any help would be appreciated.

+3
source share
2 answers

, , news/get/[index], db json formate, ,

public function yourControllerAction(){
  $news = //objects fetched from db

  //set json header
  $response = new Response();
  $response->headers->set('Content-Type', 'application/json');
  $response->setContent(json_encode($news);
  return $response;
}

javascript javascript , mustache. JMSSerializerBundle json.

+1

All Articles