AJAX response character issue

Hello

       I have problem with french character  in AJAX response. When I fetch the result using ajax the response looks like ¿a marche d¿j¿?  . But without ajax it shows the original data as ça marche déjà? . How can I solve the issue?
JacobbabyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Beverley PortlockCommented:
It looks like a character set issue. Are you encoding the the string in PHP before returning it via AJAX? Look at http://www.php.net/htmlentities and pass your string through it before returning it. That way it will be (hopefully) character set independent.
0
JacobbabyAuthor Commented:
It is partially working.  When I use htmlentities, it shows all the html elements in the data. Suppose my data is "<div class="test">ça marche déjà?</div>"  , I want to show only " ça marche déjà? ".
0
Ray PaseurCommented:
This is almost certainly a character set collision.  Please read this article for details of the issue and ways to contain it.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11880-Unicode-PHP-and-Character-Collisions.html

The use of HTMLEntities() is appropriate for the data strings, but you would not want to use it on the HTML tags that you need for proper rendering of the HTML document.  The "deep background" about HTMLEntities() is that it can be used to mitigate the risk that an external data source might contain evil JavaScript or markup that can break the layout of a web page, hence the recommendation to use it on any output to the browser.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JacobbabyAuthor Commented:
ok thank you
0
Ray PaseurCommented:
@Jacobbaby: It appears that you do not understand the grading guidelines for Experts-Exchange.  Please see the grading guidelines here:
http://support.experts-exchange.com/customer/portal/articles/481419
The asker must justify giving a C grade and give the experts an opportunity to improve it.
So why did you give this grade?

Upon looking at your profile, I see that out of the last dozen questions you've closed, you have deleted 5, and given 3 grades of "C", which is the worst possible grade you can give your colleagues at EE, where the "default" grade is "A" and your only real option is to mark the grade down to punish sloppy or uncooperative members.

I had not seen your post showing the HTML and the part about HTMLEntities(), but that, as you see, is not really the answer.  The appropriate use of HTMLEntities() would be determined by what you want to send to the browser.  If you want to send the HTML for use as markup, you would not use HTMLEntities().  If the data is from an external (tainted) source you would use strip_tags() to remove the HTML and/or HTMLEntities() to display the HTML.   Neither approach will have anything to do with the character set collision.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.