php - how can i decoding a JSON with ajax from symfony2 project? -


i'm working on symfony2 , i'm sendig json information products 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 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 client side want decoding 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 need

i think for-loop 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');         }); 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -