我想缓存从服务器接收的数据,以便执行最少数量的 PHP/MySQL 指令。我知道缓存选项是自动为 $.ajax() 设置的。但是,每次调用 $.ajax() 时我都会看到 MySQL 指令,即使 postdata 与之前的调用中的相同。我错过了什么吗?缓存从服务器接收的数据的最佳方法是什么?这是我的代码:
var postdata = {'pid':'<?php echo $project_id;?>',
'record_id':this.id};
$.ajax({
type: "POST",
url: "get_note.php",
data: postdata
}).done(function(data){
if (data != '0') {
// Add dialog content
$('#note_container').html(data);
$('#note_container').dialog();
} else {
alert(woops);
}
});
这是我的想法。当然,根据您的需要进行调整。
function getAjaxData(){
var $node = $('#note_container');
if ($node.data('ajax-cache').length == 0) {
$.ajax({
// do stuff.
success: function(data){
// Add dialog content
$node.html(data).data('ajax-cache',data).dialog();
}
});
} else {
$node.html( $node.data('ajax-cache') ).dialog();
}
}
getAjaxData();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)