Here's my script. I want the result to be cached but it keeps sending requested requests if my mouse enters it again.
$('.poplist li').mouseenter(function(){
t=$(this).parent().attr("rel");
i=$(this).attr("rel");
$.ajax({
url:"/j/place",
data:{"t":t,"tid":i},
cache:true,
success:function(data){
data= jQuery.parseJSON(da开发者_StackOverflow社区ta);
s=$('.left[rel='+t+']');
s.find('.intro').html(data["intro"]);
s.find('.shop-avat img').attr("src","http://img.douban.com/u/plao/"+data['img']);
}
})
})
jQuery.ajax's cache
option does nothing when set to true
, and caching is entirely left up to the browser. If it is set to false
, however, a cache-busting timestamp is appended to the request. That's all.
Update: To see that this is so, take a look at the the source of jQuery.ajax, version 1.6.4, line 676, here: https://github.com/jquery/jquery/blob/1.6.4/src/ajax.js#L676
A simple solution is,
You may save the result (data)
in a variable and you may use an if
function before your ajax request. On mouse enter, if variable have no data stored, trigger ajax request, else, return false.
精彩评论