Above statement was working on web2py 2.9.11 and before because of behavioral bug in web2py, which got fixed in web2py 2.9.11. Now
response.json() sets
content-type=application/json . So because of above line, on web2py >2.9.11 html code is displayed in browser instead of rendering it as html.

Correct way:

First convert python variable to json in controller and then pass it to view. And in view, use XML() to assign it to javascript variable so that it is not escaped