if/else jQuery with JSON -


my json includes pictures. have gotten pictures work when should , when shouldnt. of if/else in jquery. want if image displayed, text. want foto dispalyed if image displayed. code below not work.

the question is: want foto in json displayed when image is.

var titel = post.titel; var content = post.content; var date = post.date; var author = post.author; var foto = post.foto var image = post.image;     // if image going displayed  if (image.length >= 1){  img = '<img src="/images/' + image+'" alt="image">';  if (foto.length >= 1){     renderfoto = foto; } else{     renderfoto = ""; } // else if image should not displayed }else{ img = ""; renderfoto = ""; } 

this how json displayed. works.

var postcontent = '<div class="content-grid-info">'+img+'<div class="post-info"><h1>'+titel+' </h1><h3>datum: '+date+' author: '+author+' photo: '+foto+' </h3><p>'+content+'</p></div></div>'; posts.append(postcontent); 

json had alot of information show 2 different kinds of

{ "posts": [{      "titel": "blogginlägg 14",     "content": "'give little touch. give little push push. caress    it, gentle.'",     "date": "2016-11-03",     "author": "Åsa",     "foto": "bo morenius bmbild.se/",     "image": "post4.jpg"     },{     "titel": "blogginlägg 9",     "content": "there no limits here, start out believing here. (points @ heart)",     "date": "2016-11-03",     "author": "Åsa",     "image": ""     } ] } 

you need use different variable foto want render variable contains post.foto (just have img rendered image, , image post.image.

var foto = post.foto var image = post.image;  // if image going displayed if (image.length >= 1){     img = '<img src="/images/' + image+'" alt="image">';     if (foto.length >= 1){         renderfoto = foto;     } else{         renderfoto = "";     } // else if image should not displayed }else{     img = "";     renderfoto = ""; } 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -