<script type="text/javascript" charset="UTF-8">
doesn't seem to do the work :(
I'll start from the top, because the solutiona I am looking for might not be the one I'm asking for.
So I'm on a simple CRM. One of it's 'simple' features is to register a request from customer that is not yet in Customers
database - if CRM can't find a customer with name matching the one provided, then new customer is registered. This very popular feature leads to a lot of Customers
entities whose all but comany name atributes are empty.
Later on users do add contact attributes, but the workflow is quite slow and boring. To speed it up i wrote a python function that looks up a customer by it's name on local yellow pages, parses HTML and turns it into a dict(). It takes quite some time, so I put it on seperate query page, that is red by JavaScript upon request.
the query page renders dictionary as a string like this:
[{'name': '"AG \xc4\x80bolti\xc5\x86a b\xc5\xabvuz\xc5\x86\xc4\x93mums", SIA', 'phone': '67244222'}]
Notice literal UTF-8 coding
$.get('/zl?name=AG SIA ĀBOLTIŅA BŪVUZŅĒMUMS', function(data){...
retrieves same way it looks above. To turn retrieved dataString into Object result = eval(data)[0]
. So now $('#zl').html(result.name)
puts "AG ÄboltiÅa bÅ«vuzÅÄmums", SIA
not "ĀBOLTIŅA BŪVUZŅĒMUMS" as it should be.
I have <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
in page header and script begins with <script type="text/javascript" charset="UTF-8">
but nothing helps.
So Questions:
- how to set a proper encoding of JS output? is there some trick method like
string.toProperUTF-8()
? - Is there a way to
.decode(UTF-8)
a python dictionary without causing server error? - is there a less problematic way to do it?