Welcome Guest, Not a member yet? Register   Sign In
Characters Sent via Ajax Do Not Arrive Correctly at CI App?
#1

[eluser]Vik[/eluser]
I've got some Ajax code that sends this string to my app:

Code:
Academia-Gate — the Nanny State & The Professors: My Brief Email Exchange With The Co-Chair of the “Cry Wolf” Project

In CI, I have set:

Code:
$config['charset'] = "UTF-8";

I have my Ajax library (jQuery/getJSON) set to use UTF8, and my php environment (NetBeans) is also set to UTF8.

Using Firebug, I can see that the text variable containing the above string, does contain it correctly, at the time it is used in my Ajax call.

However, using breakpoints, I can see that when this text is received by my CI app during the Ajax, it looks like this:

Code:
Academia-Gate — the Nanny State & The Professors: My Brief Email Exchange With The Co-Chair of the “Cry Wolf” Project

How can I correct this?

Thanks in advance to all for any info.
#2

[eluser]Vik[/eluser]
Update:

I modified the php routine that receives the Ajax call, so that it sent the string back to my Javascript code in the Ajax response - and the string arrived correctly, looking just as it did when it left. I believe this means that nothing went wrong in the transmission of the string via Ajax to my CI app.

So the anomaly seems to be something in how the string is stored to mySQL. When it gets stored to mySQL, it gets stored as:

Quote:Academia-Gate ??" the Nanny State & The Professors: My Brief Email Exchange With The Co-Chair of the “Cry Wolf” Project

In other words, 2 of the anomalies are corrected, but the first one - the — in place of the dash near the beginning - is stored to mySQL as ??". When I retrieve the string from mySQL, it shows ??" instead of the original dash.

In my database config file, I have:

Code:
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";

...and in config.php I have:

Code:
$config['charset'] = "UTF-8";

How can I ensure that the string is stored correctly to mySQL?
#3

[eluser]Vik[/eluser]
Update #2:

I've tracked it down to the behavior of mysql_real_escape_string, called by the CI function escape_str in mysql_driver.php.

I've posted a question about this in the "CodeIgniter Discussion" forum.




Theme © iAndrew 2016 - Forum software by © MyBB