2017-06-03 2 views
3

Mathjax nicht dynamisch Rendering TEX Formeln von PHP/Ajax

var questions = {"ques_id":"1","question":"<p><span class=\\\"math-tex\\\">\\\\(x = {-b \\\\pm \\\\sqrt{b^2-4ac} \\\\over 2a}\\\\)<\/span>&nbsp; &nbsp;Test Question new with mathjax<\/p>","ques_type":"text_based_questions","correctAnswer":3,"choices":[{"option_id":"1","value":"Option A"},{"option_id":"2","value":"Option B"},{"option_id":"3","value":"Option C"},{"option_id":"4","value":"OPtion D"}]}; 
 

 
$('#test-question').html(questions.question); 
 
MathJax.Hub.Queue(["Typeset",MathJax.Hub, 'test-question']);
<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
    <meta charset="utf-8"> 
 
    <meta name="viewport" content="width=device-width"> 
 
    <script type="text/x-mathjax-config"> 
 
     MathJax.Hub.Config({ 
 
     showProcessingMessages: false, 
 
     tex2jax: { inlineMath: [['$','$'],['\\(','\\)']] } 
 
     }); 
 
    </script> 
 
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_HTMLorMML"> 
 
    </script> 
 
    </head> 
 
\t <body> 
 
    <h5 class="border-bottom">Instructions: Read the question, work out your answer and select the best option.</h5> 
 
    <p><span class="math-tex">\(\left(\sum_{k=1}^n a_k b_k \right)^2 \leq \left(\sum_{k=1}^n a_k^2 \right) \left(\sum_{k=1}^n b_k^2 \right) \)</span></p> 
 
\t \t <div class="question" id="test-question"></div> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> 
 
    </body> 
 
</html>

ich die folgende Frage von Ajax-Anfrage

Mathjax richtig konfiguriert ist immer aber die Frage aus dem JSON kommt nicht wiedergegeben wird von MathJax. Die Fragen werden in der MySQL-Datenbank gespeichert und von einer Ajax-Anfrage abgerufen.

Ich habe alles versucht, aber es funktioniert immer noch nicht. Bitte helfen

+0

Sie können ein Live-Beispiel mithilfe der Snippet-Funktion erstellen. Es ist wahrscheinlich ein einfaches Synchronisationsproblem, aber es gibt nicht genug Informationen. –

+0

@PeterKrautzberger Ich habe ein Code-Snippet hinzugefügt, wo das MathJax, das vom JSON kommt, nicht gerendert wird. –

Antwort

2

Von Json fügte es doppelten Schrägstrich. Plz entfernen, dass es Ihr Problem lösen wird.

+0

'question = question.replace (/ \\\\/g, '\\'); Frage = question.replace ('', ''); ' –