tabyouto / google-code-prettify

Automatically exported from code.google.com/p/google-code-prettify
Apache License 2.0
0 stars 0 forks source link

syntax highlighting is not working in ajax #316

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Calling spring controller and returning my code which need to be displayed. 
I have replaced < and > with corresponding html entity.
2. upon successful ajax call, I used .html() function to add my code wrapped 
from <pre class="prettyprint prettyprinted">...</pre> to concerned div.
3. syntaxes were not highlighted, but when I manually added above pre block 
with code to html and refreshed it... it worked.!!!

(Please include HTML, not just your source code)
<pre class="prettyprint"><div id='init_btn' class='right_bottom_txt'></div><div 
class='out-div-login'></div> <script type="text/javascript">var 
clientId="KQ5j5UO93cr3L16c";(function() {var scr = 
document.createElement('script'); scr.type = "text/javascript"; scr.async = 
true;scr.src ="http://xx.234.xx.13x:3000/js/c_content.js";var s = 
document.getElementsByTagName('script')[0]; s.parentNode.appendChild(scr, 
s);})(); </script></pre>

Code:
$.ajax({
                type    :   "POST",
                url     :   _GLOBAL_URL+"/s/getScript",
                data    :   {button_position:button_position},
                beforeSend : function(jqXHR)
                {
                    $("#c_install").append(loadIcon.addLoader("c_install"));
                },
                success : function(response,status,jqxhr)
                {
                    if(response)
                    {
                        loadIcon.removeLoader("c_install");
                        var elem = "<pre class=\"prettyprint\">"+response+"</pre>";
                        $("#c_install").parent().html(elem);
//                      document.getElementById("cht_install").parentNode.innerHTML = elem;
                    }
                },
                error   : function(jqXHR,status,errorthrown)
                {
                    loadIcon.removeLoader("c_install");
                    bootbox.alert("There was some error while generating script..");
                },
                complete : function(jqXHR,status)
                {
                    loadIcon.removeLoader("c_install");
                }
            });

What is the expected output?  What do you see instead?
Expected was highlighted syntax, but I just saw plain text wrapped with pre tag 
with respective prettyprint class.

What version are you using?  On what browser?
I am using latest version from google cdn as provided. I am using latest 
firefox and chrome browser.. didnt check with IE.

Please provide any additional information below.

Original issue reported on code.google.com by aman.a.g...@gmail.com on 7 Nov 2013 at 4:02

GoogleCodeExporter commented 9 years ago
Ah.. I found the solution. after some trials.
I first created pre tag using javascript
then I added respective prettify class into it,
then I added my code
then I appended to my dom element
and finally I called prettyPrint() function.. and it worked..!!

Original comment by aman.a.g...@gmail.com on 8 Nov 2013 at 5:56

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I am not understanding what you did to get this to work with ajax.
could you please provide a demo of it working?

Thank you
wayne

Original comment by wa...@cffcs.com on 1 Mar 2015 at 10:31