{"id":344,"date":"2021-11-22T07:10:06","date_gmt":"2021-11-21T23:10:06","guid":{"rendered":"http:\/\/blog.yuekegu.com\/?p=344"},"modified":"2021-11-22T07:10:06","modified_gmt":"2021-11-21T23:10:06","slug":"%e8%a7%a3%e5%86%b3%e5%8a%a8%e6%80%81ajax-pjax%e5%8a%a0%e8%bd%bdmathjax%e4%b8%8d%e7%94%9f%e6%95%88%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/book.yuekegu.com\/index.php\/2021\/11\/22\/%e8%a7%a3%e5%86%b3%e5%8a%a8%e6%80%81ajax-pjax%e5%8a%a0%e8%bd%bdmathjax%e4%b8%8d%e7%94%9f%e6%95%88%e9%97%ae%e9%a2%98\/","title":{"rendered":"\u89e3\u51b3\u52a8\u6001ajax\/pjax\u52a0\u8f7dmathjax\u4e0d\u751f\u6548\u95ee\u9898"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html>\n&lt;html>\n&lt;head>\n&lt;title>MathJax TeX Test Page&lt;\/title>\n&lt;script type=\"text\/x-mathjax-config\">\n  MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\\\(','\\\\)']]}});\n&lt;\/script>\n&lt;script type=\"text\/javascript\" async\n  src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/mathjax\/2.7.5\/MathJax.js?config=TeX-MML-AM_CHTML\">\n&lt;\/script>\n&lt;\/head>\n&lt;body>\nWhen $a \\ne 0$, there are two solutions to \\(ax^2 + bx + c = 0\\) and they are\n$$x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.$$\n&lt;\/body>\n&lt;\/html><\/code><\/pre>\n\n\n\n<p>\n\n\u53ea\u8981\u5f15\u5165mathjax\u7684js\u5730\u5740\uff0c\u914d\u7f6econfig\uff0c\u5c31\u80fd\u81ea\u52a8\u8bc6\u522b\u6587\u7ae0\u4e2d\u7684\u6570\u5b66\u516c\u5f0f\u5199\u6cd5\u3002\u663e\u793a\u6548\u679c\u5982\u4e0b\uff1a\n\n<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.yuekegu.com\/wp-content\/uploads\/2021\/11\/2597553-78c150ee69feef381.jpg\" alt=\"\" class=\"wp-image-345\"\/><\/figure>\n\n\n\n<p>\u6b63\u5e38\u60c5\u51b5\u4e0b\u4f7f\u7528\uff0c\u662f\u53ef\u4ee5\u5b9e\u73b0\u663e\u793a\u6570\u5b66\u516c\u5f0f\u7684\uff0c\u4f46\u662f\u5982\u679c\u4f60\u7684\u9875\u9762\u4f7f\u7528\u4e86\u52a8\u6001\u52a0\u8f7d\uff0c\u5373ajax\u6216pjax\u7684\u60c5\u51b5\u4e0b\uff0cmathjax\u5c31\u4e0d\u80fd\u987a\u5229\u7684\u6e32\u67d3\u51fa\u6570\u5b66\u516c\u5f0f\u4e86\u3002<\/p>\n\n\n\n<p>\u54b3\u54b3\uff0c\u89e3\u51b3\u52a8\u6001\u9002\u914d\u7684\u4e8b\u60c5\u4e5f\u4e0d\u662f\u4e00\u6b21\u4e24\u6b21\u4e86\uff0c\u6dfb\u52a0\u4e8b\u4ef6\u53ef\u4ee5\u7528jquery\u7684on\u65b9\u6cd5\u59d4\u6258\u3002\u5728\u52a8\u6001\u8c03\u7528\u540e\u6267\u884c\u53ef\u4ee5\u5728$.ajax\u7684success\u65b9\u6cd5\u540e\u6267\u884c\u76f8\u5173\u4e1a\u52a1\u903b\u8f91\u3002 pjax\u5219\u5728complete\u6216end\u540e\u6267\u884c\u76f8\u5173\u4e1a\u52a1\u903b\u8f91\u4ee3\u7801\u3002\u8fd9\u91cc\u6211\u62ffpjax\u505a\u6f14\u793a\uff0c\u4ee3\u7801\u7c7b\u4f3c\u4e0b\u9762\uff1a<\/p>\n\n\n\n \n\n\n\n<pre class=\"wp-block-code\"><code>$(document).pjax('a[target!=_top]', '#page', {\n    fragment: '#page',\n    timeout: 8000,\n}).on('pjax:send', function () {\n    do something\n}).on('pjax:complete', function () {\n    $.getScript(\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/mathjax\/2.7.4\/MathJax.js?config=TeX-MML-AM_CHTML\", function() {\n        MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\\\(','\\\\)']]}});\n    });\n});<\/code><\/pre>\n\n\n\n<p> \u60f3\u6cd5\u662f\u5728pjax\u52a0\u8f7dcomplete\u4e4b\u540e\u52a0\u8f7dmathjax\u7684js\u4f9d\u8d56\uff0c\u5728\u914d\u7f6econfig,\u56e0\u4e3a\u4e4b\u524d\u6b63\u5e38\u4f7f\u7528\u4e5f\u662f\u8fd9\u6837\u7684\u3002\u4f46\u662f\u5f88\u9057\u61be\uff0c\u8fd8\u662f\u6ca1\u6709\u6b63\u5e38\u663e\u793a\u3002 <\/p>\n\n\n\n<p>\n\n\u540e\u6765\u9532\u800c\u4e0d\u820d\u7684\u627e\u5230\u4e86MathJax.Hub.Typeset()\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u7ed3\u5408Queue\u65b9\u6cd5\u5c31\u80fd\u5b9e\u73b0\uff08\u4e0d\u8981\u95ee\u6211\u4e3a\u5565\u662f\u4e2d\u6587\u6587\u6863\uff0c\u8c37\u6b4c\u7ffb\u8bd1\u4e86\u89e3\u4e0b\uff09\n\n<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>....\n.on('pjax:complete', function () {\n    $.getScript(\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/mathjax\/2.7.4\/MathJax.js?config=TeX-MML-AM_CHTML\", function() {\n        MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\\\(','\\\\)']]}});\n        \/\/ entry-content\u662f\u6587\u7ae0\u9875\u7684\u5185\u5bb9div\u7684class\n        var math = document.getElementsByClassName(\"entry-content\")[0];\n        MathJax.Hub.Queue([\"Typeset\",MathJax.Hub,math]);\n    });\n});<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u53ea\u8981\u5f15\u5165mathjax\u7684js\u5730\u5740\uff0c\u914d\u7f6econfig\uff0c\u5c31\u80fd\u81ea\u52a8\u8bc6\u522b\u6587\u7ae0\u4e2d\u7684\u6570\u5b66\u516c\u5f0f\u5199\u6cd5\u3002\u663e\u793a\u6548\u679c\u5982\u4e0b\uff1a \u6b63\u5e38\u60c5\u51b5\u4e0b\u4f7f\u7528\uff0c\u662f\u53ef\u4ee5\u5b9e\u73b0\u663e\u793a\u6570\u5b66\u516c\u5f0f\u7684\uff0c\u4f46\u662f\u5982\u679c\u4f60\u7684\u9875\u9762\u4f7f\u7528\u4e86\u52a8\u6001\u52a0\u8f7d\uff0c\u5373ajax\u6216pjax\u7684\u60c5\u51b5\u4e0b\uff0cmathjax\u5c31\u4e0d\u80fd\u987a\u5229\u7684\u6e32\u67d3\u51fa\u6570\u5b66\u516c\u5f0f\u4e86\u3002 \u54b3\u54b3\uff0c\u89e3\u51b3\u52a8\u6001\u9002\u914d\u7684\u4e8b\u60c5\u4e5f\u4e0d\u662f\u4e00\u6b21\u4e24\u6b21\u4e86\uff0c\u6dfb\u52a0\u4e8b\u4ef6\u53ef\u4ee5\u7528jquery\u7684on\u65b9\u6cd5\u59d4\u6258\u3002\u5728\u52a8\u6001\u8c03\u7528\u540e\u6267\u884c\u53ef\u4ee5\u5728$.ajax\u7684success\u65b9\u6cd5\u540e\u6267\u884c\u76f8\u5173\u4e1a\u52a1\u903b\u8f91\u3002 pjax\u5219\u5728complete\u6216end\u540e\u6267\u884c\u76f8\u5173\u4e1a\u52a1\u903b\u8f91\u4ee3\u7801\u3002\u8fd9\u91cc\u6211\u62ffpjax\u505a\u6f14\u793a\uff0c\u4ee3\u7801\u7c7b\u4f3c\u4e0b\u9762\uff1a \u60f3\u6cd5\u662f\u5728pjax\u52a0\u8f7dcomplete\u4e4b\u540e\u52a0\u8f7dmathjax\u7684js\u4f9d\u8d56\uff0c\u5728\u914d\u7f6econfig,\u56e0\u4e3a\u4e4b\u524d\u6b63\u5e38\u4f7f\u7528\u4e5f\u662f\u8fd9\u6837\u7684\u3002\u4f46\u662f\u5f88\u9057\u61be\uff0c\u8fd8\u662f\u6ca1\u6709\u6b63\u5e38\u663e\u793a\u3002 \u540e\u6765\u9532\u800c\u4e0d\u820d\u7684\u627e\u5230\u4e86MathJax.Hub.Typeset()\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u7ed3\u5408Queue\u65b9\u6cd5\u5c31\u80fd\u5b9e\u73b0\uff08\u4e0d\u8981\u95ee\u6211\u4e3a\u5565\u662f\u4e2d\u6587\u6587\u6863\uff0c\u8c37\u6b4c\u7ffb\u8bd1\u4e86\u89e3\u4e0b\uff09<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"class_list":["post-344","post","type-post","status-publish","format-standard","hentry","category-27"],"_links":{"self":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/posts\/344","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/comments?post=344"}],"version-history":[{"count":0,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/posts\/344\/revisions"}],"wp:attachment":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/media?parent=344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/categories?post=344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/tags?post=344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}