Pass Finnish character to ajax request and get junk character (skandinavian charachters)

I have found some of character passes ajax through php file and get stange output (skandinavian charachters)

I pass data with escape() function [escape(output)]. see in bellow snippet

Passed such string to ajax call:
Klikkaa lisätäksesi
tekstiä

and get result of such string
Klikkaa lis�t�ksesi
teksti�

what's problem occure in this script

var callBackActUrl = "dvk.eirikvae.aum"
var textdata = "text="+escape(output);
jQuery.ajax({
type: "POST",
url: callBackActUrl,
data: textdata,
cache: false,
success:function(responseText){
alert(responseText);

}
});


Solution :
I had read lot of artical on google and find solution for. I passed data in ajax using escape function, we replaced escape() function with
encodeURIComponent() and it is working proper.

var textdata = "text="+encodeURIComponent(output);

This method will encode certain chars that would normally be recognized as special chars for URIs.

No comments: