Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
function GetProductDetails(barcodeId,coords) 
{
    $.getJSON("api/products/?barcodeId=" + barcodeId  + "&latitude=" + coords.latitude + "&longitude=" + coords.longitude)
      .done(function (data) {
         
          console.log(data);
          if (data.results == null) {

              $('#result').append(data.message)
          }

          else
          {
              var ul = $("<ul></ul>");
              ul.append(data.results.retailername);
              ul.append(data.results.productname);
              ul.append(data.results.price);
              ul.append(data.results.distance)
          }        
      });
}
Posted
v3
Comments
Do you see your data on Console?
klein_jnr 12-Dec-13 2:07am    
Thank you Tadit no i dont see my data on my console and i would also like to know how i would iterate or go through each object while using the code that you showed me because my data result object is an array of 2 using something like $.each(data, function (key, item) and i only see undefined appearing on my html page as my list,Thank you for your help
Do something like below...

$.each( data.items, function( i, item ) {
// Here try to get the data from "item". Check by putting debugger.
});
klein_jnr 12-Dec-13 3:51am    
Thank you so much Talip, i managed to display everything the way you told me to go about like this. Product Details
Thank you for shopping with us details will be sent to you shortly
ShopName :Shoprite
Name : DogFood
Rand :150
Distance in Km :8309559.355265908
ShopName :Spar
Name : DogFood
Rand :100
Distance in Km :16471269.62219214 but now i need to to separate the list in two parts for readabilty purposes, so that if there are many shops that have the searched product the shopname with all the other items will be added but they should be grouped together i tried the </br> tags but just makes spaces between each item and dont make spaces between two groups, your help is appriciated i am very new to all this
Ok post the updated which you are using now. I will try to modify.

1 solution

You need to append that ul to another div or something then append all the li to that ul like below...
C#
else
{
    var list = $("#result").append('<ul></ul>').find('ul');

    list.append('<li>' + data.results.retailername + '</li>');
    list.append('<li>' + data.results.productname + '</li>');
    list.append('<li>' + data.results.price + '</li>');
    list.append('<li>' + data.results.distance + '</li>');
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900