javascript - Send JSON Object to HTML -
in html code, have javascript. in order check whether code worked/became json object, first sent json object in blank html print out json.
{"nodes": [{"id": "latin 2"}, {"id": "latin 2"}, {"id": "computer science 2"}, {"id": "calculus 2"}], "links": [{"id": 1, "target": "latin 1", "source": "latin 2"}, {"id": 2, "target": "latin 1", "source": "latin 2"}, {"id": 3, "target": "computer science 1", "source": "computer science 2"}, {"id": 4, "target": "calculus 1", "source": "calculus 2"}]}
you can see did render json object, when wanted put json object in javascript, inside html, error code:
{"nodes": [{"id": "physics 5"}, {"id": "latin 2"}, {"id": "latin 2"}, {"id": "computer science 2"}, {"id": "calculus 2"},
i using gae jinja send on json object.
#graph information--> turning json json_graph = json.dumps(graph) template_vars = {'json_data': json_graph } template = jinja2_environment.get_template('template/index.html') self.response.write(template.render(template_vars))
this html javascript embedded
<script> //json_data python var graph = {{json_data}} </script>
Comments
Post a Comment