Stack Exchange
how can i decoding a JSON with ajax from symfony2 project?
I'm currently working on a symfony2 and i'm sendig a JSON information about my products from my controller 
public function getProduitsOnJSONAction()
{
    $em = $this->container->get('doctrine')->getEntityManager();
    $produits = $em->getRepository('BTBundle:Produit')->findAll();
    //start  bloc reponse json
        $encoders = array(new JsonEncoder());
        $normalizers = array(new GetSetMethodNormalizer());
        $serializer = new Serializer($normalizers, $encoders);
        // passed data $produits
        $response = new Response($serializer->serialize($produits, 'json')); 
        $response->headers->set('Content-Type', 'application/json');
        return $response;
    // end bloc json response

}

the JSON from this URL ('http://localhost/BusinessTracker/web/app_dev.php/getProduitsJSON'): 
[{"id":1,"refProduit":"1265466","nomProduit":"Yagourt","prixProduit":270,"stockProduit":10,"libelleProduit":"Yagourt D\u00e9lice"},{"id":2,"refProduit":"000001","nomProduit":"Nutella","prixProduit":4500,"stockProduit":15,"libelleProduit":"Chocolat Nutella"},{"id":3,"refProduit":"000002","nomProduit":"Lait D\u00e9lice","prixProduit":950,"stockProduit":30,"libelleProduit":"1L de Lait d\u00e9lice"}]

and now from the client side i want to decoding this JSON via ajax 
$.getJSON('http://localhost/BusinessTracker/web/app_dev.php/getProduitsJSON', function(data) {
                  var items = [];

                  $.each(data, function(key, val) {
                    items.push('<li id="' + key + '">' + val + '</li>');
                  });

                  $('<ul/>', {
                    'class': 'my-new-list',
                    html: items.join('')
                  }).appendTo('body');
            });

and nothing happens. Please i need a help 

Do you get any error in the console ? Did you try printing data in the console to help you debug ? $.getJSON('http://localhost/BusinessTracker/web/app_dev.php/getProduitsJSON', function(data) { console.log(data); // ...

when you access http://localhost/BusinessTracker/web/app_dev.php/getProduitsJSON do you get a JSON output?

yes when i access to http://localhost/BusinessTracker/web/app_dev.php/getProduitsJSON iget the JSON output

I think your for-loop is slightly off:
$.getJSON('http://localhost/BusinessTracker/web/app_dev.php/getProduitsJSON', function(data) {
              var items = [];

              data.each(function(obj) {
                items.push('<li id="' + obj.id + '">' + obj.nomProduit + '</li>');
              });

              $('<ul/>', {
                'class': 'my-new-list',
                html: items.join('')
              }).appendTo('body');
        });

