gpt4 book ai didi

php - jquery php mysql 和 json 返回循环数据

转载 作者:行者123 更新时间:2023-11-29 08:50:32 26 4
gpt4 key购买 nike

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

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

最佳答案

只需在 JavaScript 中循环即可:

function (data)
{
for(company_nr in data)
{
$('#'+continent).append('<li>'+data[company_nr].country+' '+data[company_nr].company+'</li>')
}
}

关于php - jquery php mysql 和 json 返回循环数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11360873/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com