I have an object "company". When I use company inside of html, it works fine. But when I tried to use that object inside javascript I get the "Uncaught SyntaxError: Unexpected token &".
What I am trying to do is getting the objects from db then display them on html page then change up some divs using js.
the url:
('^all_companies$', 'companies.views.all_companies')
the view:
def all_companies(request):
companies = Company.objects.all().order_by('id')[:5];
return direct_to_template(request, 'all_companies.html', {'companies': companies} );
the html:
{% block sidebar %}
<div id="sidebar">
<!-- like google maps, short list of company info -->
<ul>
{% for comp in companies %}
<li>{{ comp }}</li>
{% endfor %}
</ul>
</div>
{% endblock %}
the js:
var tmp = {{ companies }}
{{ companies }}
evaluate to? Javascript doesn't seem to like that syntax. – Greg Apr 27 '12 at 22:11companies
to JSON - only then JS would be able to read it – hamczu Apr 27 '12 at 22:12