gpt4 book ai didi

javascript - $.ajax() 打印一组未打印的 jsonObjects

转载 作者:行者123 更新时间:2023-11-30 16:41:26 25 4
gpt4 key购买 nike

我有一组 json 对象,它们将由 $.ajax() 检索并打印在表中。但是,尽管网页通过 XAMPP(在网络 >> xhr 中看到)检索它们,但我无法打印。有人可以帮忙吗?

JSON:

{"people":[
{"firstName":"Peter","lastName":"De'Souza","blogURL":"www.google.com"},
{"firstName":"Romeo","lastName":"Cherolov","blogURL":"www.google.com"},
{"firstName":"Caspian","lastName":"Monovola","blogURL":"www.google.com"}
{"firstName":"Sita","lastName":"Martin","blogURL":"www.google.com"}
{"firstName":"Rina","lastName":"Schenoi","blogURL":"www.google.com"}
]}

jQuery:

$.ajax({
type: 'POST',
url: 'http://localhost/example4/data.json',
data: { patientID: "1" },
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(jsonData) {

for (i=0;i<5;i++)
{
console.log(jsonData[i].firstName);
}

},
error: function() {
alert('Some Error');
}
});

它只是抛出错误警报,尽管在 Network >> xhr 中我可以看到正在获取“people - json 对象数组”。请帮忙!

最佳答案

尝试 console.log(jsonData.people[i].firstName);

关于javascript - $.ajax() 打印一组未打印的 jsonObjects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31920332/

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