我需要根据以下方案将数据库内容加载到变量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];
}
}
});
});