我正在使用MathJax在我的网页上排版方程式。在第一次加载网页时,一切正常。点击“下一步”按钮,div内的等式改变(ajax调用),但它显示为'raw TEX',即Mathjax第二次不进行排版。相关代码如下:
MARKUP AND SCRIPT
<div class="div_body" id="ques_dashboard">
<p>When $a \ne 0$, there are two solutions to \(ax^2 + bx + c = 0\) and they are $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$</p>
</div>
<div class="div_footer">
<a href="#" class="button ryt_btn" id="answer_submit">SUBMIT</a>
<a href="#" class="button ryt_btn" id="next_q">NEXT</a>
<a href="#" class="button ryt_btn" id="skip_q">SKIP</a>
</div>
<script>
$(document).ready(function(){
$('#next_q').click(function(){
$("#next_q").hide();
$('#answer_submit').show();
$("#skip_q").show();
$.ajax({
type: 'POST',
url: '../ajax/next_question.php',
//data:{queslist:queslist, current_qorder:current_qorder},
success: function(msg){
$('#ques_dashboard').html(msg);
MathJax.Hub.Queue(["Typeset",MathJax.Hub,'ques_dashboard']);
}
});
return false;
});
});
</script>
由AJAX调用的PHP
<?php?>
<p> If \\(a, b, c\\) are in HP, then \\(\\frac {1}{a}, \\frac {1}{b}, \\frac {1}{c}\\) are in AP</p>
我在这里介绍了简化代码,其中包括大量的php和mysql。我成功地能够显示“下一个问题”,但无法使用Mathjax排版。我尝试过使用MathJax.Hub.Queue
函数。
我是jquery和ajax的新手。请帮忙。
答案 0 :(得分:1)
问题是您需要转义'\'
个字符,否则它们会被jquery
和基础javascript
解释。所以返回的字符串应该是这样的:
<?php?>
<p> If \\(a, b, c\\) are in HP, then \\(\\frac {1}{a}, \\frac {1}{b}, \\frac {1}{c}\\) are in AP</p>
答案 1 :(得分:0)
我能够在Julien的帮助下追踪问题。下面给出的代码片段在ajax调用之后干扰了排版。(此Queue函数隐藏文本直到排版完成。)
MathJax.Hub.Queue(function () {
document.getElementById("hide_page").style.visibility = "";});
评论这部分解决了这个问题。
如果我找到了一种使用ajax和“一直隐藏到排版”功能的方法,我会更新答案。