- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How do I populate my ionic list with thumbnail dynamically? The code below brings me the data from my db successfully but I am having some issues appending each value to each list item. item.nome and item.dia shows me "undefined" values;
$(document).on("click", "#submit", function(evt) { /* your code goes here */ var state = $("#state").val(); var city = $("#city").val(); var dataString = "state="+state+"&city="+city+"&submit="; var $server; $server = 'http://localhost/project'; function Lista(){ $.ajax({ type: "post", url: $server+"/check.php", data: dataString, success: function(data) { var data = $.parseJSON(data); var estado = data[0]; var cidade = data[1]; var nome = data[2]; var local = data[3]; var dia = data[4]; var horario = data[5]; //alert(nome); activate_page("#list"); $.each(data, function(index, item){ var list_item = '<ion-item class="item widget uib_w_14 d-margins item-thumbnail-left" data-uib="ionic/list_item_avatar" data-ver="0">'; list_item += '<img src="images/Strabburg.jpg" id="thumb">'; list_item += '<h2>'+item.nome+'</h2>'; list_item += '<p>'+item.dia+'</p>'; list_item += '</ion-item>'; $("#lista").append(list_item); }); } }); } new Lista(); });
check.php
if(isset($_POST['submit'])){ $estado = $_POST['state']; $cidade = $_POST['city']; $sql = "SELECT * FROM table WHERE state = '".$estado."' and city = '".$cidade."' "; $result = mysqli_query($mysqli, $sql); $totalrows = mysqli_num_rows($result); if($totalrows > 0){ //echo "success"; while($Linha = mysqli_fetch_array($result)){ $state[] = $Linha['state']; $city[] = $Linha['city']; $name[] = $Linha['name']; $place[] = $Linha['place']; $date[] = $Linha['date']; $time[] = $Linha['time']; } $output = json_encode(array($state, $city, $name, $place, $date, $time)); echo $output; }else{ echo "failed"; } }
- Tags:
- HTML5
- Intel® XDK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Madson,
Seems that json_encode in your php is not working as needed. The result of echo $output should be something with this structure:
[{"a":1,"b":2,"c":3,"d":4,"e":5},
{"a":1,"b":2,"c":3,"d":4,"e":5},
{"a":1,"b":2,"c":3,"d":4,"e":5}]
I'm not very experiencied in php, used it long time ago, if you manage to get an output like this I will be glad to help you with XDK part. json_encode has several parameters,
Regards,
Diego
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try this, but not knowing how is data, I'm not sure it works:
var data = $.parseJSON(data); for(var i=0; i<data.length; i++){ var list_item = '<ion-item class="item widget uib_w_14 d-margins item-thumbnail-left" data-uib="ionic/list_item_avatar" data-ver="0">'; list_item += '<img src="images/Strabburg.jpg" id="thumb">'; list_item += '<h2>'+data.nome+'</h2>'; list_item += '<p>'+data.dia+'</p>'; list_item += '</ion-item>'; $("#lista").append(list_item); }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Cannot post the string here I don´t know why
What is the easier way? Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
do you mean this? I am very new to xdk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, please do the same after
var
data = $.parseJSON(data);
add this
console.log(JSON.stringify(data));
Regards,
Diego
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
First and second results
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please check my edited question with php file too
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Madson,
Seems that json_encode in your php is not working as needed. The result of echo $output should be something with this structure:
[{"a":1,"b":2,"c":3,"d":4,"e":5},
{"a":1,"b":2,"c":3,"d":4,"e":5},
{"a":1,"b":2,"c":3,"d":4,"e":5}]
I'm not very experiencied in php, used it long time ago, if you manage to get an output like this I will be glad to help you with XDK part. json_encode has several parameters,
Regards,
Diego
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok, I solved it fixing php according to http://diegocavalca.com/parte-4-construindo-a-api-para-integracao-de-dados/
Thanks for your time.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page