0

I havent tried this before and my solution hasnt worked.

In mysql I would be able to write it using a while loop but im trying to pull the data through ajax.

Can someone help

var qString = 'country=' +country+'&continent='+continent;

$.post('/assets/inc/get-country.php', qString, function (data) {    
    $('#'+continent).append('<li>'+data[0].country+' '+data[0].company+'</li>');
}, "json");

The above returns in console.log's ajax response the following

[{
    "continent": "Europe",
    "country": "Spain",
    "company": "Universidade de Vigo CITI",
    "comments": "We are very satisfied with the disrupter. It's equipment is very easy to use and effective in breaking cells. I also would like to thank Constant System for for the assistance provided."
}, {
    "continent": "Europe",
    "country": "Spain",
    "company": "IPLA",
    "comments": "The Constant Systems cell disruptor has made extraction of membrane proteins from Gram positives a reproducible and efficient task in our lab."
}]

How can I get this to display as an li list on my page?

Thanks in advance

EDIT

$("#comments-tabs div.country a").click(function(e){
    e.preventDefault();
    var continent = $(this).parent().attr("id");
    var country = $(this).attr("name");
    console.log(continent+country);
var qString = 'country=' +country+'&continent='+continent;
    $.post('/assets/inc/get-country.php', qString, function (data) {    
        for(company_nr in data){
            $('#'+continent).append('<li>'+data[company_nr].country+' '+data[company_nr].company+'</li>')
        }
    }, "json");
});

1 Answer 1

2

Just loop it in javascript:

function (data)
{
   for(company_nr in data)
   {
      $('#'+continent).append('<li>'+data[company_nr].country+' '+data[company_nr].company+'</li>')
   }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.