0
My Ionic app stores user data, as a name, in localStorage. I went for a test, logged in my wife’s name, Flávia, but when I looked at the console in the Resources tab, the name field was null and the id had her user id. I went to the bank and changed her name, I removed the accent from the letter a. I went back, I logged and her name appeared! Do you know if localStorage allows you to store accented names? If not, how should I do?
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.");
}
})
}
})
login.html is saved as utf8-without-good by your text editor (Notepad++ or sublimetext for example)?
– Guilherme Nascimento
After that line,
}else if(typeof(Storage) !== "undefined") {
, add thatconsole.log("Nome: "+response.nome);
. Test using an accentuated name and see what appears on the browser console. On Chrome, pressCtr+Shift+I
– Daniel Omine
It’s @Danielomine, it looked like this on the console: Name: null .
– GustavoSevero
I suspected from the beginning.. It can be the script on the page
ww/php/login.php
that is returning wrong. Check what is wrong with this script because apparently there is no error in the javascript that presented the question.– Daniel Omine
Exactly @Danielomine, I put a print_r on at the end of login.php to see how the data is coming and just see how the name is: Array ( [idUsuario] => 45 [idCep] => 66 [userUsuario] => C [name] => Fl via Schneider [email] => [email protected] ) How can I fix this in php?
– GustavoSevero
configure the php environment’s Find. There are several topics here on the subject. It’s a rather complicated and extensive subject to explain in the comments. Check which database charset and configure php according to the database charset. Basically.
– Daniel Omine
No, the database charset is utf8, but from what I saw I have to do handling the name variable in php itself
– GustavoSevero
so blz, I can’t say and say "do X, do Y", but I think you can just add the header in the php file.
header('Content-Type: text/html; charset=utf-8');
. Also check that the text editor you used to edit the PHP file is asutf-8 without bom
. Also check what returns the functionecho mb_internal_encoding(); exit;
. But they are only guesses. As I said, there is no way to solve without knowing how the whole environment really is. Note that even the database configured as utf8, the data may be being recorded erroneously with another charset, ie corrupted.– Daniel Omine