I have a Python Flask web application that I want to pass a dictionary dataset from javascript, I'm trying to use JSON. I can pass numbers in order, but it seems to generate an error when using strings.
Here is a snippet of python code generating a JSON string: view.py
def dumpdata(): DB_name={"name":"aaragh"} strng=json.dumps(DB_name) return render_template('dumpdata.html',result = strng)
Here is the resulting dumpdata.html HTML file
<html><body> <p >{{ result }}</a> <script> var data = JSON.parse({{result}}); console.log(data.name); </script> </body></html>
Here is the error message and console output: ConsoleLog
SyntaxError: invalid dumpdata property id: 4
<html><body> <p >{"name": "aaragh"}</a> <script> var data = JSON.parse({"name": "aaragh"}); console.log(data.name); </script> </body></html>
I don't think this is relevant, but I get the same error on both ubuntu chrome and win IE.
Any ideas? I think I am missing something obvious, but I hit my head about it for several days and I still have not been able to find a solution ...
thanks
source share