gpt4 book ai didi

jquery - 将数据库内容加载到变量中

转载 作者:行者123 更新时间:2023-12-01 05:00:15 25 4
gpt4 key购买 nike

我需要根据以下方案将数据库内容加载到变量data中。

var data = {
"62": {
sku: "62",
section: "bodyImage",
img: "images/diy-images/config-images/62.png",
label: "plain red",
price: "100"
},
"63": {
sku: "63",
section: "bodyImage",
img: "images/diy-images/config-images/63.png",
label: "plain pink",
price: "110"
},
"360": {
sku: "360",
section: "bodyImage",
img: "images/diy-images/config-images/360.png",
label: "plain gray",
price: "120"
},
};​

我尝试使用以下函数来实现这一点,但没有成功。我错过了什么?

var data = (function() {
$.ajax({
url: 'get_data.php',
data: "",
dataType: 'json',
success: function(rows) {
for (var i in rows) {
var row = rows[i];

var id = row[0];
var section = row[1];
var img = row[2];
var label = row[3];
var price = row[4];
}
}
});
});​

最佳答案

可以通过'.'获取json对象值运算符

var data = (function() {

$.ajax({
url: 'get_data.php',
data: "",
dataType: 'json',
success: function(rows) {
for (var i in rows) {

var id = row.sku;
var section = row.section;
var img = row.img;
var label = row.label;
var price = row.price;

}
}
});

});​

关于jquery - 将数据库内容加载到变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10861759/

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