0
我已經爲產品創建了一個圖片庫,並在其上有兩個不同的視圖。每次選擇視圖時,都會向服務器發送ajax請求,並返回一個json對象。我的代碼目前的作品,但即時通訊擔心它可以做得更快,我不知道如果$ .empty()真的清除內存中的JSON對象。向服務器發送單個ajax請求,試圖在jquery中多次重複使用對象
代碼:
<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數據再利用而無需撥打另一個電話?
是的,這似乎是一個簡單的變量範圍問題,而不是ajax *本身*。 –