LocalStorage does not save names with an accent?

0

My ionic app stores user data, such as name, in localStorage. I went to do a test, I logged in with the name of my wife, Flavia, but when I looked at the console in the Resources tab, the name field was null and the id had its user id. I went to the bank to change her name, I took the accent from the letter a. I came back, I logged in and her name appeared! Do you know if localStorage allows you to store names with an accent? If not, how should I do it?

Part of index.html:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>

My login.html:

<ion-view title="Login" hide-back-button="true">
<ion-content overflow-scroll="true" padding="true" class="has-header">
    <form class="list">
        <ion-list>
            <div ng-controller="loginCtrl">
                <label class="item item-input">
                    <input type="text" ng-model="usuario.email" placeholder="E-mail">
                </label>
                <label class="item item-input">
                    <input type="password" ng-model="usuario.senha" placeholder="Senha">
                </label>
            </ion-list>
            <div class="spacer" style="height: 40px;"></div>
            <button class="button button-stable button-block" ng-click="logar(usuario)">Entrar</button>
            <!--<a href="#/salas" class="button button-stable button-block ">Entrar</a> -->
            <a href="#/cadastroCep" class="button button-stable button-block ">Cadastre-se</a>
            <div align="center">{{msgErro}}</div>
            </div>
    </form>
</ion-content>

My controller.js

.controller('loginCtrl', function ($scope, $http, $state, $location, $window) {

$scope.usuario = {
    email: "",
    senha: ""
}

$scope.msgErro = '';

$scope.msgExiste = '';

$scope.logar = function (usuario) {

    $http.post("http://www.vigilantescomunitarios.com/www/php/login.php", usuario).success(function (response){

        if(response == ''){
            $location.path('/page10');
            $scope.msgErro = "E-mail ou senha inválido";

        }else if(typeof(Storage) !== "undefined") {
                    $window.localStorage.setItem("idUsuario", response.idUsuario);
                    $window.localStorage.setItem("idCep", response.idCep);
                    $window.localStorage.setItem("nome", response.nome);
                    $location.path('/salas');
                } else {
                    console.log("Desculpe, mas o navegador nao possui suporte a Web Storage.");
                }
      })
   }
})

Console Print:

    
asked by anonymous 17.02.2016 / 18:55

2 answers

1

This occurs because the www/php/login.php file is coming with no accents

  

I always tell you to post the code that can be reproduced, but it seems that you always fail in this, once again please to avoid difficulties in helping you follow the tips of this link: link

I do not know how your PHP is, but for the accents to work you have to do as in this answer:

  • Doubt with charset = iso-8859-1 and utf8

    • Save all PHP and HTML documents with the same utf8 encoding without BOM or ANSI (do not use ANSI if your bank is utf8)
    • If it is utf8 you should open the connection like this (in your login.php) if you will use PDO:

      $conn = new PDO('mysql:host=HOST;dbname=BANCO;charset=utf-8', 'USUARIO', 'SENHA');
      $conn->exec('SET CHARACTER SET utf8');//Define o charset como UTF-8
      

      or so if you use mysqli:

      $mysqli = new mysqli('HOST', 'usuario', 'senha', 'banco');
      
      if (false === $mysqli->set_charset('utf8')) {
          printf('Error ao usar utf8: %s', $mysqli->error);
      }
      
  

Do not use the old mysql API for PHP (those starting with mysql_ ):

     
    
18.02.2016 / 01:38
-1

It seems to be the encoding of your file. In the <head> part of your index.html add this line:

<meta charset="utf-8"/>
    
17.02.2016 / 19:03