ajax test

(function ($) {

function loadNode(obj){
obj.closest('.filter').find('.item').removeClass('select');
obj.parent().addClass('select');
$(".channel-list").html(obj.data('cache'));
}

var filter = $('.filter'),
item = filter.find('.item')

item.on('click','a',function(){
var $this = $(this),
_this = this,
id = $this.parent().attr("date-id");

//data存在
if($this.data('cache')){
loadNode($this);
return false
}

$.ajax({
type:"GET",
dataType: "text",
url:'/data/js/'+id+'.js?'+Math.ceil(new Date()/3600000),

beforeSend:function(){
if(_this.ajaxStatus){return false} //ajax状态开关
_this.ajaxStatus = true;
},

success:function(datas){
$this.data('cache',datas);
loadNode($this);
},

error: function(XMLHttpRequest, textStatus, errorThrown) {
_this.ajaxStatus = false;
//console.log(XMLHttpRequest.status);
//console.log(XMLHttpRequest.readyState);
//console.log(textStatus);
}

});
return false
})

})(jQuery);

 

posted @ 2014-02-28 23:06  {前端开发}  阅读(391)  评论(0编辑  收藏  举报