$(function () {
$.ajax({
url: './js/data.json',
type: 'get',
dataType: 'json',
timeout: 1000,
beforeSend: LoadFunction, //加载执行方法
error: erryFunction, //错误执行方法
success: succFunction //成功执行方法
});
function LoadFunction() {$("#list").html('加载中...');}
function erryFunction() {alert("error");}
function succFunction(data) {
$("#list").html('');
//eval将字符串转成对象数组
var json2 = eval(data); //数组
console.log(json2["code"]);
let msg1 = json2["msg"];
json2 = json2["data"];
$.each(json2, function (index, item) {
//循环获取数据
var imgUrl = json2[index].imgUrl;
var price = json2[index].price;
var name = json2[index].name;
// $("#js_list").html($("#js_list").html() + "
" + imgUrl + " - " + price + " - " + name + "
");
$("#js_list").html($("#js_list").html() +
'
\n')});
}
});