[英]jquery php mysql and json returning looped data
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. 在mysql中,我可以使用while循环编写它,但我试图通过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 以上内容在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."
}]
How can I get this to display as an li list on my page? 如何将其显示为我页面上的li列表?
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");
});
Just loop it in javascript: 只需在javascript中循环:
function (data)
{
for(company_nr in data)
{
$('#'+continent).append('<li>'+data[company_nr].country+' '+data[company_nr].company+'</li>')
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.