如何在Silex插入帖子中使用jQuery ajax

I'm trying to do some insert into the database then view the post list and display it by ajax, but i'm not pretty sure how to do it.

Here's my route:

$app->match('/status', 'Post\StatusPost\Controller\StatusPostController::statusAction')->bind('main');

Then on my controller I process the insert stuffs then access the Model entity and pass it into the view

$posts = new Post();
$posts = $posts->allPosts($app);

return $app['twig']->render('status.html.twig', [
  'form' => $form->createView(),
  'posts' => $app->json($posts),
]);

Then on my view there's just a simple text area. So upon submitting the post it should display it via ajax

Here's my js script

$('#status-btn').click(function(){
$.getJSON('/status', function(data){
  console.log(data);
  var html;
  $.each(data, function(entryIndex, entry){
    html += '<div class="status-container">';
    html += '<h3 class="status-title">' + entry.name + '</h3>';
    html += '<img src="' + window.location.href + '/images/' + entry.image + '">';
    html += '<p class="status-content">' + entry.status + '</p>';
    html += '<span class="status-time">' + entry.timestamp + '</p>';
    html += '</div>';
  });
  $('.content-container').html(html);
}); 

});

But upon submitting it nothing happens.

It looks like that you say GetJSON, but you send Html? cannot work. you should send a JsonResponse or you must set the Headers properly 'Content-Type: application/json'. If you use GetJSON the browser tries automatically convert the response from the php script (no matter if its silex) and the header must be of type JSON.