0

我以前没有尝试过,我的解决方案没有奏效。

在 mysql 中,我可以使用 while 循环来编写它,但我试图通过 ajax 提取数据。

有人可以帮忙吗

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");

以上在 console.log 的 ajax 响应中返回以下内容

[{
    "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."
}]

我怎样才能让它在我的页面上显示为 li 列表?

提前致谢

编辑

$("#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");
});
4

1 回答 1

2

只需在javascript中循环它:

function (data)
{
   for(company_nr in data)
   {
      $('#'+continent).append('<li>'+data[company_nr].country+' '+data[company_nr].company+'</li>')
   }
}
于 2012-07-06T11:06:32.723 回答