I am relatively new to web development and even less familiar when it comes to the front end side. I've got a problem regarding an encoding issue.
- environment: python 2.7, Flask
I am sending json data to a server like this.
@app.route("/test")
def test():
data = json.dumps({"name": "홍길동", "id": "gildong1"}, ensure_ascii=False)
return render_template("testpage.html", data=data)
I printed out the data on the server side and it prints Korean characters just fine.
But whenever I receive the data in javascript like this:
var t_data = JSON.parse({{data}});
The result in the console is like this:
var t_data = JSON.parse({"name": "홍길동", "id": "gildong1"});
Update
I am suspicious of the content-type header. When I inspected it through the debugger, I found that the Content-Type header is u'text/html'. So I tried to change my code like this, but it still prints unicode:
@app.route("/test")
def test():
data = json.dumps({"name":"홍길동", "id": "gildong1"}, ensure_ascii=False).encode("utf8")
resp = make_response(render_template("TestPage.html", data=data))
resp.headers['Content-Type'] = 'text/html'
return resp