定义思维吧 关注:14贴子:53
  • 0回复贴,共1

夜深了,水一帖 ajax

只看楼主收藏回复

var ajax_a="#left a,#middle a, #right .jv-post-items a, #right .jv-tab a,#right .jv-tags-wrap a,#right .jv-new-comment a,#right .jv-cat a";var ajax_load_div=*<div id="inlojv_ajax_loading_frame"></div><div title="页面正在加载中..." id="inlojv_ajax_loading"><div></div></div>*;var ajax_content=*#middle*;$(document).ready(function(){ajax_loadPage_Init()});function body_am(id){id=isNaN(id)?$(*#*+id).offset().top:id;$("body,html").animate({scrollTop:id},800);return false}function inlojv_ajax_load(url,state){if(history&&history.pushState){if(state!==true){history.pushState(null,document.title,url)}}else{if(url.indexOf(*#*)==0){return false}ajx_loading=true;window.location.hash=*!*+url}$.ajax({url:url,dataType:*HTML*,cache:false,beforeSend:function(){$(ajax_load_div).appendTo(*body*)},timeout:15000,error:function(){$(*#inlojv_ajax_loading_frame,#inlojv_ajax_loading*).remove();location.href=url},success:function(data){var title=data.match(/<title>(.*?)<\/title>/)[1];var content=$(data).find(ajax_content).html();document.title=title;$(ajax_content).html(content);data=content=null},complete:function(){$(*#inlojv_ajax_loading_frame,#inlojv_ajax_loading*).remove()}});var anchor=url.indexOf(*#*);if(anchor==-1){body_am(0)}else{anchor=url.substring(anchor+1);body_am(anchor)}}function ajax_loadPage_Init(){$(ajax_a).live("click",function(){var url=$(this).attr(*href*);inlojv_ajax_load(url);return false})}if(history&&history.pushState){ajx_loading=true;$(window).on(*popstate*,function(e){if(e.originalEvent.cancelable&&ajx_loading){ajx_loading=false;return false}if(location.hash==**){inlojv_ajax_load(location.href,true)}})}else{$(window).on(*hashchange*,function(){if(ajx_loading===false){var url=location.hash;if(url.indexOf(*#!*)!=-1){url=url.replace(/^#!/,**)}else if(url==*#*||url==**){url=location.href}inlojv_ajax_load(url)}ajx_loading=false})}


IP属地:广西1楼2014-08-06 01:16回复