Ajax缓存,减少后台服务器压力
// Ajax缓存 请求一次,页面不会在次访问这个方法,会读取缓存数据
var reqScanTips; //定义一个
var cacheScanTips = {}; //放数据的
$(document).delegate(".routeScanTips","mouseenter", function () {
var $this = $(this);
var billcode = $(this).attr("data-sitecode");
var scanuser = $(this).attr("data-scanuser");
var key = "A027" + billcode + scanuser;
if (isCache) {
if (cacheScanTips[key] != null) {
$this.manhua_bubbletips({ position: "t", value: 35, content: cacheScanTips[key] + "", last: true });
} else {
postData();
}
} else {
postData();
}
function postData() {
reqScanTips = $.ajax({
type: "post",
dataType: "json",
url: "/postdate.aspx",
data: "id=" + billcode + "&type=A888&scanuser=" + scanuser,
cache: true,
timeout: 20000,
success: function (msg) {
if (msg.Result[0]["status"] == "true") {
$this.manhua_bubbletips({ position: "t", value: 35, content: msg.Result[0]["tel"] + "", last: true });
cacheScanTips[key] = msg.Result[0]["tel"];
}
}
});
}
});