I'm doing an ajax callback that's supposed to update a div with new text:

# action
...
return 'jQuery("#my-target").html("%s");' % clean_str(make_contents(filename
))


def make_contents(filename):
    return open(filename, 'rb').read().decode('utf-8')


def clean_str(text):
    return str(text).replace('"', '\\"').replace("’", "'")......and so on


Problem is I've run into a funny string 

begin offending text

 
end offending text



that chokes the jQuery somewhere inside of web2py.js and causes the text to 
not get displayed in the target div.

Firebug complains:


   1. Uncaught SyntaxError: Unexpected token ILLEGAL 
web2py.js:21<http://127.0.0.1:8000/YAKiToMe/static/js/web2py.js>
      1. 
jQuery.ajax.successweb2py.js:21<http://127.0.0.1:8000/YAKiToMe/static/js/web2py.js>
      2. 
ojquery-1.7.2.min.js:3<http://127.0.0.1:8000/YAKiToMe/static/js/jquery/jquery-1.7.2.min.js>
      3. 
p.fireWithjquery-1.7.2.min.js:3<http://127.0.0.1:8000/YAKiToMe/static/js/jquery/jquery-1.7.2.min.js>
      4. 
wjquery-1.7.2.min.js:5<http://127.0.0.1:8000/YAKiToMe/static/js/jquery/jquery-1.7.2.min.js>
      5. 
      2. d jquery-1.7.2.min.js:5
   
   I suspect this is an encoding problem. I suspect the text unfolds to a 
   quote that messes up the .html("%s") part of the jQuery. But this has me 
   stumped. Any help is appreciated. Thanks.
   

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to