mysql - PHP not receveing characters with accents from Ajax -


this question has answer here:

i made script in ajax recovers data mysql , gives php when select option changed:

$country = $_post['country']; $sql = "select id,name regions idcountry='$country' order name asc"; $result = mysqli_query($connexion->db, $sql); $count_row = $result->num_rows;  $regions_arr = array();  while( $row = mysqli_fetch_array($result) ){     $idregion = $row['id'];     $nameregion = htmlentities($row['name']);      $regions_arr[] = array("id" => $idregion, "name" => $nameregion); } // encoding array json format echo json_encode($regions_arr); 

and in php page have script:

<script> $(document).ready(function(){ $("#sel_country").change(function(){     var countryid = $(this).val();      $.ajax({         url: '/include/ajax/getregions.php',         type: 'post',         data: {country:countryid},         datatype: 'json',         success:function(response){              var len = response.length;              $("#sel_region").empty();             for( var = 0; i<len; i++){                 var id = response[i]['id'];                 var name = response[i]['name'];                  $("#sel_region").append("<option value='"+id+"'>"+name+"</option>");              }         }     }); }); }); </script> 

everything works @ has to, except of names recovered have special characters, instance "genève" or "zürich". values not showed @ all, option has correct value id looks empty in name.

i searched , tried uriencode doesn't seem change, idea how fix this? thank you!

update , solution

i solved changing tables utf8m64 in way (for each table):

alter table `table_name` convert character set utf8mb4 collate utf8mb4_unicode_ci; 

then in script ajax added this:

mysqli_set_charset($link, 'utf8mb4'); 

and works :)

try this

$.ajax({   url: "mydomain.com/url",   type: "post",   datatype: "xml/html/script/json", // expected format response   contenttype: "application/json" }); 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -