\u6ce8\uff1a\u4ee3\u7801\u6781\u4e0d\u89c4\u8303\uff08\u6211\u672c\u6765\u5c31\u4e0d\u662f\u4e13\u4e1a\u7684\uff09\uff0c\u559c\u6b22\u5c31\u62ff\u53bb\u5427\uff0c\u4e0d\u8fc7\u82e5\u8981\u8f6c\u8f7d\u5c31\u8bf7\u4fdd\u7559\u672c\u7ad9\u4e00\u4e2a\u94fe\u63a5\u3002<\/p><\/blockquote>\n\n\n\n
\u7279\u522b\u5efa\u8bae\uff1a\u6709\u4e00\u5b9ajs\u57fa\u7840\u7684\u670b\u53cb\u4f7f\u7528\uff0c\u80fd\u81ea\u5df1\u4f18\u5316\u5c31\u81ea\u5df1\u4f18\u5316\uff0c\u6ca1\u63a5\u89e6\u8fc7\u7684\u8fd8\u662f\u522b\u6298\u817e\u4e86\uff0c\u4e0d\u4f1a\u5219\u81ea\u884c\u767e\u5ea6\uff0c\u4e0b\u9762\u7684\u6ce8\u91ca\u90fd\u662f\u6211\u5f53\u521d\u4e00\u53e5\u53e5\u767e\u5ea6\u6298\u817e\u5b66\u4e60jq\u624d\u52a0\u4e0a\u53bb\u7684\u3002<\/p><\/blockquote>\n\n\n\n
\/\/\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\n\/\/ Packaged PJAX By INLOJV 2015.01.09\n\/\/ \u9875\u9762\u3001\u641c\u7d22\u3001\u8bc4\u8bba\u3001\u8bc4\u8bba\u5206\u9875 PJAX\n\/\/\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\n\n\/\/ \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 AJAX-\u8bc4\u8bba\u3001\u641c\u7d22\u3001\u5206\u9875 \u7b49\nvar ajx_main = '#main' , \/\/ \u8981\u66ff\u6362\u7684\u4e3b\u4f53id\uff0c\u6539\u4e3a\u4f60\u6587\u7ae0\u90e8\u5206\u7684\u5bb9\u5668\najx_a = 'a' , \/\/ a\u6807\u7b7e\uff0c\u81ea\u5df1\u6dfb\u52a0\u6392\u9664\u89c4\u5219\najx_comt = 'comments' , \/\/ \u6574\u4e2a\u8bc4\u8bba\u533a\u7684id ,\u4e0d\u52a0#\najx_submit_form = '#comment_form' , \/\/ \u63d0\u4ea4\u6309\u94ae\u6240\u5728\u7684\u8868\u5355\najx_comtlist = '.comment-list' , \/\/ \u8bc4\u8bba\u5217\u8868id\u6216class\najx_comtpagenav = '.pagenav' , \/\/ \u8bc4\u8bba\u5206\u9875\u5bfc\u822a\u7684id\u6216class\najx_comtpagenav_a = '.pagenav a' , \/\/ \u8bc4\u8bba\u5206\u9875\u5bfc\u822a\u7684a\u6807\u7b7e\najx_sform = '.inlo-search form' , \/\/ \u641c\u7d22\u8868\u5355form\u6807\u7b7e\najx_skey = '.s-key' ; \/\/ \u641c\u7d22\u8868\u5355input\u6807\u7b7e\u5185\u7684id\u6216class\nfunction reload_func(){\n \/\/ \u8fd9\u91cc\u653e\u7f6e\u9700\u8981\u91cd\u8f7d\u7684JS\u6216\u51fd\u6570\n}\n\n\n$(function() { \n a(); \/\/pushState\u521d\u59cb\u5316\u6267\u884c\u4e00\u6b21\n});\n\/\/ \u5efa\u7acb\u951a\u70b9\u51fd\u6570\uff0c\u7528\u4e8e\u8df3\u8f6c\u540e\u7684\u6eda\u52a8\u5b9a\u4f4d\uff0c\u4f7f\u7528\u8fd9\u4e2a\u4e3b\u8981\u662f\u6709\u4fa7\u680f\u8bc4\u8bba\u5e26#\u53f7\u65f6\u80fd\u5728\u8bf7\u6c42\u540e\u5b9a\u4f4d\u5230\u8be5\u6761\u8bc4\u8bba\u7684\u4f4d\u7f6e\nfunction body_am(id) { \n id = isNaN(id) ? $('#' + id).offset().top : id;\n $(\"body,html\").animate({\n scrollTop: id\n }, 0);\n return false;\n}\nfunction to_am(url) { \n var anchor = location.hash.indexOf('#'); \/\/ \u7528indexOf\u68c0\u67e5location.href\u4e2d\u662f\u5426\u542b\u6709'#'\u53f7\uff0c\u5982\u679c\u6ca1\u6709\u5219\u8fd4\u56de\u503c\u4e3a-1\n anchor = window.location.hash.substring(anchor + 1);\n body_am(anchor);\n}\n\/\/ \u4e3b\u9875\u5730\u5740\uff0c\u7528\u4e8e\u4e0b\u9762\u7684\u63d0\u4ea4\u51fd\u6570\nvar home_url = document.location.href.match(\/http:\\\/\\\/([^\\\/]+)\\\/\/i)[0]; \n\/\/ \u51fd\u6570\uff1a \u66ff\u6362url\uff0c\u7528\u4e8e\u8bc4\u8bbaajax\u63d0\u4ea4\nfunction replaceUrl(url, domain) {\n return url.replace(\/http:\\\/\\\/([^\\\/]+)\\\/\/i, domain);\n}\n\/\/ \u51fd\u6570\uff1a\u4ece\u5c01\u88c5\u7684Json\u83b7\u53d6\nfunction getFormJson(frm) {\n var o = {};\n var a = $(frm).serializeArray();\n $.each(a,\n function() {\n if (o[this.name] !== undefined) {\n if (!o[this.name].push) {\n o[this.name] = [o[this.name]];\n }\n o[this.name].push(this.value || '');\n } else {\n o[this.name] = this.value || '';\n }\n });\n return o;\n}\n\/\/ \u51fd\u6570\uff1a\u66f4\u65b0\u6d4f\u89c8\u5668\u5386\u53f2\u7f13\u5b58\uff08\u7528\u4e8e\u6d4f\u89c8\u5668\u540e\u9000\uff09\nfunction l(){\n history.replaceState( \/\/ \u5237\u65b0\u5386\u53f2\u70b9\u4fdd\u5b58\u7684\u6570\u636e\uff0c\u7ed9state\u586b\u5165\u6b63\u786e\u7684\u5185\u5bb9\n { url: window.document.location.href,\n title: window.document.title,\n html: $(document).find(ajx_main).html(), \/\/ \u6293\u53d6\u4e3b\u4f53\u90e8\u5206outerHTML\u7528\u4e8e\u5448\u73b0\u65b0\u7684\u4e3b\u4f53\u3002\u4e5f\u53ef\u4ee5\u7528\u8fd9\u53e5 html: $(ajx_main).prop('outerHTML'),\n }, window.document.title, document.location.href);\n}\n\/\/ \u51fd\u6570\uff1a\u9875\u9762\u8f7d\u5165\u521d\u59cb\u4e00\u6b21\uff0c\u89e3\u51b3Chrome\u6d4f\u89c8\u5668\u521d\u59cb\u8f7d\u5165\u65f6\u4ea7\u751fajax\u6548\u679c\u7684\u95ee\u9898,\u5e76\u4e14\u76d1\u542c\u524d\u8fdb\u540e\u9000\u4e8b\u4ef6\nfunction a(){\n window.addEventListener( 'popstate', function( e ){ \/\/\u76d1\u542c\u6d4f\u89c8\u5668\u540e\u9000\u4e8b\u4ef6\n if( e.state ){\n document.title = e.state.title;\n $(ajx_main).html( e.state.html ); \/\/\u4e5f\u53ef\u4ee5\u7528replaceWith \uff0c\u6700\u540e\u8fd9\u4e2ahtml\u5c31\u662f\u4e0a\u9762\u66ff\u6362State\u540e\u91cc\u9762\u7684html\u503c \n \/\/ \u91cd\u8f7djs\n window.load = reload_func(); \/\/ \u91cd\u8f7d\u51fd\u6570\n }\n }); \n}\n\/\/\u51fd\u6570\uff1aAJAX\u6838\u5fc3\nfunction ajax(reqUrl, msg, method, data) {\n if (msg == 'pagelink' || msg == 'search') { \/\/ \u9875\u9762\u3001\u641c\u7d22\n $(ajx_main).fadeTo('slow',0.6); \n } else if ( msg == 'comment' ){ \/\/ \u8bc4\u8bba\u63d0\u4ea4 \n $('#' + ajx_comt).fadeTo('slow',0.5); \n } else if ( msg == 'comtpagenav' ){ \/\/ \u8bc4\u8bba\u5206\u9875\u65f6\n $(ajx_comtlist).fadeTo('slow',0.5);\n $(ajx_comtpagenav).fadeTo('slow',0.8);\n }\n $.ajax({\n url: reqUrl, \n type: method,\n data: data,\n beforeSend : function () { \/\/\u52a0\u8f7d\u524d\u64cd\u4f5c \u8fd9\u4e2a\u5fc5\u987b\u653e\u5728window.history.pushState()\u4e4b\u524d\uff0c\u5426\u5219\u4f1a\u51fa\u73b0\u903b\u8f91\u9519\u8bef\u3002 \n l(); \/\/\u5237\u65b0\u5386\u53f2\u70b9\u5185\u5bb9\uff0c\u8fd9\u4e2a\u5fc5\u987b\u653e\u5728window.history.pushState()\u4e4b\u524d\uff0c\u5426\u5219\u4f1a\u51fa\u73b0\u903b\u8f91\u9519\u8bef\u3002\n },\n success: function(data) {\n if (msg == 'pagelink' || msg == 'search') { \/\/ \u53c8\u5982\u679cmsg\u4e3a \u9875\u9762 \u6216 \u641c\u7d22\u2014\u2014 \u30101\u3011\n $(ajx_main).html($(data).find(ajx_main).html()) ; \/\/ \u66ff\u6362\u539f#main\u7684\u5185\u5bb9\n $(ajx_main).fadeTo('normal',1);\n } else if (msg == 'comment') { \/\/ \u53c8\u5982\u679cmsg\u4e3a \u8bc4\u8bba\u56de\u590d\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u30102\u3011 \n $('#' + ajx_comt).html($(data).find('#' + ajx_comt).html());\/\/ \u8bc4\u8bba\u5217\u8868\u6ed1\u51fa\n $('#' + ajx_comt).fadeTo('normal',1); \n $(\"body,html\").animate({scrollTop:$('#'+ajx_comt).offset().top}, 900); \/\/ \u5b9a\u4f4d\u8fd4\u56de\u8bc4\u8bbaID\u9876\u90e8\n } else if (msg == 'comtpagenav') { \/\/ \u53c8\u5982\u679cmsg\u4e3a \u8bc4\u8bba\u5206\u9875\u2014\u2014\u30103\u3011\n var content = $(data).find(ajx_main).html();\n var pagedstring = $(data).find(ajx_comtpagenav).html();\n $(ajx_main).html(content);\n $(ajx_comtpagenav).html(pagedstring);\n $(ajx_comtlist).fadeTo('normal',1); \/\/ \u8bc4\u8bba\u5217\u8868\u663e\u793a\n $(ajx_comtpagenav).fadeTo('normal',1); \/\/ \u8bc4\u8bba\u5206\u9875\u663e\u793a\n $(\"body,html\").animate({scrollTop:$(ajx_comtlist).offset().top}, 600); \n }\n document.title = $(data).filter(\"title\").text(); \/\/ \u6d4f\u89c8\u5668\u6807\u9898\u53d8\u66f4\n if (msg != 'comment') { \/\/ \u2014\u2014 \u4e0d\u4e3a\u540e\u9000 \u4e5f \u4e0d\u4e3a\u8bc4\u8bba\u56de\u590d\u65f6\n var state = { \/\/ \u8bbe\u7f6estate\u53c2\u6570\n url: reqUrl,\n title: $(data).filter(\"title\").text(),\n html: $(data).find(ajx_main).html(),\n };\n \/\/ \u5c06\u5f53\u524durl\u548c\u5386\u53f2url\u6dfb\u52a0\u5230\u6d4f\u89c8\u5668\u5f53\u4e2d\uff0c\u7528\u4e8e\u540e\u9000\u3002\u91cc\u9762\u4e09\u4e2a\u503c\u5206\u522b\u662f: state, title, url\n window.history.pushState(state, $(data).filter(\"title\").text(), reqUrl);\n }\n },\n complete: function() { \/\/ ajax\u5b8c\u6210\u540e\u52a0\u8f7d\n \/\/ \u4ee3\u7801\u91cd\u8f7d\u533a\n if (msg == 'pagelink') { \/\/ \u82e5msg\u4e3a \u9875\u9762\u94fe\u63a5\n to_am(reqUrl) ;\/\/ \u5b9a\u4f4d\u5230\u76f8\u5e94\u94fe\u63a5\u4f4d\u7f6e,\u8fd9\u4e2a\u5fc5\u987b\u653e\u5728window.history...\u4e4b\u540e\u6267\u884c\uff0c\u5426\u5219\u9047\u5230\u5e26#\u53f7\u7684\u94fe\u63a5\uff0c\u518d\u70b9\u51fb\u5176\u4ed6\u94fe\u63a5\u5730\u5740\u680f\u5c31\u65e0\u6cd5\u6539\u53d8\n } \n window.load = reload_func(); \/\/ \u91cd\u8f7d\u51fd\u6570\n },\n timeout: 5000, \/\/ \u8d85\u65f6\u957f\u5ea6 \n error: function(request) { \/\/ \u9519\u8bef\u65f6\u7684\u5904\u7406\n if (msg == msg == 'pagelink' || msg == 'search'){\n location.href = reqUrl; \/\/\u76f4\u63a5\u5237\u65b0\u8df3\u8f6c\u5230\u8bf7\u6c42\u7684\u9875\u9762\u94fe\u63a5\n } else if (msg == 'comment') { \/\/ \u82e5msg\u4e3a\u8bc4\u8bba\u56de\u590d\n alert($(request.responseText).filter(\"p\").text()); \/\/ \u5f39\u51fa\u8b66\u544a,\u8fd9\u4e2a\u662f\u5fc5\u9700\u7684\uff0c\u5982\u679c\u5220\u9664\u90a3\u4e48\u63d0\u4ea4\u9519\u8bef\u65f6\u5c31\u4f1a\u6253\u5f00\u7a7a\u767d\u9875\u9762\n $('#' + ajx_comt).fadeTo('normal',1); \n } else if ( msg == 'comtpagenav' ) {\n $(ajx_comtlist).fadeTo('normal',1); \/\/ \u8b66\u544a\u540e\u8bc4\u8bba\u533a\u663e\u793a\n $(ajx_comtpagenav).fadeTo('normal',1); \/\/ \u8b66\u544a\u540e\u8bc4\u8bba\u533a\u663e\u793a\n } else {\n location.href = reqUrl; \/\/\u9875\u9762\u9519\u8bef\u65f6\u8df3\u8f6c\u5230\u8bf7\u6c42\u7684\u9875\u9762\n }\n },\n });\n}\n\/\/\u9875\u9762ajax\n$('body').on(\"click\",ajx_a,\nfunction() {\n ajax($(this).attr(\"href\"), 'pagelink');\n return false;\n});\n\/\/\u8bc4\u8bbaajax\n$('body').on('submit',ajx_submit_form, \nfunction() {\n ajax(replaceUrl(this.action, home_url), 'comment', 'POST', getFormJson(this));\n return false;\n});\n\/\/\u641c\u7d22ajax\n$('body').on('submit',ajx_sform, \nfunction() {\n ajax(this.action + '?s=' + $(this).find(ajx_skey).val(), 'search'); \n return false;\n});\n\/\/\u8bc4\u8bba\u5206\u9875ajax\n$('body').on(\"click\",ajx_comtpagenav_a,\nfunction() {\n ajax($(this).attr(\"href\"), 'comtpagenav');\n return false;\n});<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"INLOJV\u5c01\u88c5\u7684\u81ea\u7528WordPress\u5168\u7ad9PJAX\u4ee3\u7801\u3002\u5305\u62ec\u6700\u7b80\u5355\u7684\u8bc4\u8bbaajax\uff0c\u66f4\u5feb\u901f\u7684\u524d\u8fdb\u540e\u9000\u529f\u80fd<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[185,204],"collection":[],"class_list":["post-12599","post","type-post","status-publish","format-standard","hentry","tag-wp-development"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/posts\/12599"}],"collection":[{"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/comments?post=12599"}],"version-history":[{"count":0,"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/posts\/12599\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/media?parent=12599"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/categories?post=12599"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/tags?post=12599"},{"taxonomy":"collection","embeddable":true,"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/collection?post=12599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}