1

I use this code to receive data from an php file

$.ajax({
                url: "includes/cpf.inc.php",
                type: "POST",
                data:{p_request:"1bdd249a5d673a721be31d7444af81af1af4c5b6",
                        p_userid:"<?php echo $dbu_userid; ?>",
                        p_curpass:$("#txtcurpass").val(),
                        p_newpass:$("#txtnewpass").val(),
                        p_cnewpass:$("#txtcnewpass").val()
                },
                cache:false,
                success:function(msg){
                    $("#chPassLoad").css("visibility","hidden");
                    wilPrompt("#chpasStat",msg.substr(0,1),msg.substr(2));
                    if(msg.substr(0,1)=="0"){
                        $("#txtcurpass").attr("value","");
                        $("#txtnewpass").attr("value","");
                        $("#txtcnewpass").attr("value","");
                    }
                },
                beforeSend:function(){
                    $("#chPassLoad").css("visibility","visible");
                }
            });

and the data that will be receive from cpf.inc.php contains html entities like this

&#12362;&#12399;&#12424;&#12358;&#12372;&#12374;&#12356;&#12414;&#12377;&#28450;&#23383

and that html entities are Japanese characters

おはようございます漢字

now my problem is when I will receive data from the variable msg it returns something like this

pX[h&sigmaf;&#1794;

Is there any code I need to append on the $.ajax parameters to encode this html entities correctly? thanks

1
  • is your scripting language on server side returning you the correct characters?? Commented Sep 22, 2011 at 5:36

2 Answers 2

1

I am guessing that you need to set the charset for the request.. here is how you can do it:

$.ajaxSetup({
    'beforeSend' : function(xhr) {
        xhr.overrideMimeType('text/html; charset=UTF-8');   //set the right charset here
    },
});

or

$.ajax({
                url: "includes/cpf.inc.php",
                type: "POST",
                data:{p_request:"1bdd249a5d673a721be31d7444af81af1af4c5b6",
                        p_userid:"<?php echo $dbu_userid; ?>",
                        p_curpass:$("#txtcurpass").val(),
                        p_newpass:$("#txtnewpass").val(),
                        p_cnewpass:$("#txtcnewpass").val()
                },
                cache:false,
                success:function(msg){
                    $("#chPassLoad").css("visibility","hidden");
                    wilPrompt("#chpasStat",msg.substr(0,1),msg.substr(2));
                    if(msg.substr(0,1)=="0"){
                        $("#txtcurpass").attr("value","");
                        $("#txtnewpass").attr("value","");
                        $("#txtcnewpass").attr("value","");
                    }
                },
                beforeSend:function(xhr) {
                         xhr.overrideMimeType('text/html; charset=UTF-8');
                         $("#chPassLoad").css("visibility","visible");
                         }
       });
Sign up to request clarification or add additional context in comments.

Comments

0

I faced same problem using PHP base64_encode($str) to pass XML code to jquery and decode the string with jQuery.base64. JPN fonts get problem / Chinese fonts is normal.

Use htmlentities($str,,'utf-8') instead of base64_encode is OK.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.