0

I post data from client to php, here is how my post data seems in client: enter image description here

I click add and post this string to php with ajax call here how posted data seem in ajax parameter;

//username ="Uğur Akkaynak" so its ok. 

    var params = {
        action: "saveAdObjects",
        username_: username,
    }
    $.ajax({
        url: "../../Controller/ActiveDirectoryController.php5",
        type: "POST",
        async:false,
        dataType: "json",
        data: params,
        success: function (result)...

In php file I check the posted variable:

var user = $_POST["username"]; //UÄŸur Akkaynak wtf!

so problem is clear, strings broken in php, I know I need change encoding in php file and tried these:

header('Content-type: text/plain; charset=utf-8'); 
utf8_encode($_POST["username"]);// Uğur Akkaynak 
mb_convert_encoding ($_POST["username"],'utf-8'); // UÄŸur Akkaynak

What should I do get $_POST["username"] as 'Uğur Akkaynak' like posted from client

  • Maybe this helps? http://stackoverflow.com/questions/13517189/turkish-characters-are-not-displayed-correctly – toesslab Oct 22 '15 at 09:49
  • Where/how/when exactly are you seeing "UÄŸur"? Most likely there's **nothing wrong** here at all, only your method of displaying the string is messed up. – deceze Oct 22 '15 at 09:53
  • What is the encoding of the HTML page? It should match the encoding you're using in PHP. You could try echo '' – Mrk Fldig Oct 22 '15 at 09:56

2 Answers2

0

There's no need to add the header:

header('Content-type: text/plain; charset=utf-8'); 

To encode strings on the client side, you could add the following in the ajax function: contentType:"application/x-javascript; charset:UTF-8"

$.ajax({
        url: "../../Controller/ActiveDirectoryController.php5",
        type: "POST",
        async:false,
        dataType: "json",
        data: params,
        contentType:"application/x-javascript; charset:UTF-8"
        success: function (result)...

Also verify that your HTML-head contains:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
toesslab
  • 5,092
  • 8
  • 43
  • 62
-1

First of all you need to observe your request via developer console.
Find about network request and see the parameter value.

if it not correct try add

contentType: "application/x-www-form-urlencoded;charset=utf-8",

into your ajax request.

ZenithS
  • 987
  • 8
  • 20