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);