javascript - $.each() jQuery newsfeed -


i'm trying make newsfeed work on website. shows news , loops of them expired ones. able add news via webpage, json may change. php script generating json following :

[     {     "0": "monsieur",     "1": "x",     "2": "24",     "3": "236",     "4": "artichauts",     "5": "4",     "6": "2015-06-19",     "7": "2015-06-26",     "8": "9",     "9": "7",     "nom": "monsieur",     "prenom": "x",     "id_promotion": "24",     "id_commercant": "236",     "article": "artichauts",     "rubrique": "4",     "date_debut": "2015-06-19",     "date_fin": "2015-06-26",     "prix_origine": "9",     "prix_promotion": "7" }, {     "0": "monsieur",     "1": "x",     "2": "23",     "3": "236",     "4": "betteraves",     "5": "4",     "6": "2015-06-18",     "7": "2015-06-25",     "8": "8",     "9": "6",     "nom": "monsieur",     "prenom": "x",     "id_promotion": "23",     "id_commercant": "236",     "article": "betteraves",     "rubrique": "4",     "date_debut": "2015-06-18",     "date_fin": "2015-06-25",     "prix_origine": "8",     "prix_promotion": "6" } ] 

and jquery script (trying) show them

$(document).ready(function () {     function newsfeed() {         $.getjson("newsfeed.php", function (result) {             var htmldata = "";             $.each(result, function (key) {                 $("#news").html(result[key].nom + " " + result[key].prenom + " has special offer : " + result[key].article + " @ " + result[key].prix_promotion + "€ instead of " + result[key].prix_origine + "€ ").delay(5000).slideup(300)                     .delay(500)                     .fadein(400);             });             x = settimeout(function () {                 newsfeed()             }, 5000);         });     }     newsfeed(); }); 

so code outputting

monsieur x has special offer : betteraves @ 6€ instead of 8€

so problem is, $.each() function not working i'd to. if has idea, appreciate.

$("#news").html inside loop replacing entire contents of #news looped element.

create html inside each , inject div after completing loop.

    var htmldata = '' ;     $.each(result, function(key){         htmldata += result[key].nom + " " + result[key].prenom + " has special offer : " + result[key].article + " @ " + result[key].prix_promotion + "€ instead of " + result[key].prix_origine + "€ ";     });     $('#news').html(htmldata); 

Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -