我为产品创建了一个图片库,并有 2 个不同的视图。每次选择一个视图时,都会向服务器发送一个 ajax 请求并返回一个 json 对象。我的代码目前可以工作,但我担心它可以变得更快,而且我不确定 $.empty() 是否真的从内存中清除了 json 对象。
编码:
<div id=grid2></div>
<div id=grid4></div>
<section id=maindisplay>
$.ajax({ // DEFAULT VIEW
url: 'query.php',
data: "",
dataType: 'json',
success: ajaxfunction
});
function ajaxfunction(json_data){
console.log (json_data)
//format json_data here in to a table
$("#maindisplay").append(table);
}
$("#grid2").click(function(){
$.ajax({
url: 'query.php',
data: "",
dataType: 'json',
success: ajaxfunction2
});
});
function ajaxfunction2(json_data){ //ONE OF THE GRID VIEWS
$("#maindisplay").empty();
console.log (json_data)
//format json_data here in to a table
$("#maindisplay").append(table);
}
</section>
我已经尝试过,但是我可以使用 json 数据在本地创建另一个对象以供重用而无需再次调用吗?