Accent error with xmlhttp.open (or in PHP) using AngujarJs / Ionic [duplicate]

0

I'm having problems with accentuation in sending form data to the database, it gets the wrong accent, type = No = No.

How could you solve this problem?

Here are my codes:

My Controller:

// ENVIAR DADOS            
    $scope.configura = [];
    // ENVIAR DADOS            
    $scope.CadastraConfiguracoes = function () {

        $ionicLoading.show();

        var url = "?cod_fornecedor=" + $scope.cod_fornecedor + "&tem_delivery=" + $scope.configura.tem_delivery + "&custo_padrao=" + $scope.configura.custo_padrao + "&frete_gratis=" + $scope.configura.frete_gratis + "&valor_minimo_frete_gratis=" + $scope.configura.valor_minimo_frete_gratis + "&tipos_pagamentos=" + window.localStorage.getItem('formas_escolhidas') + "&prazo_entrega_min=" + window.localStorage.getItem("prazo_min_entrega") + "&prazo_entrega_max=" + $scope.entrega_max + "&agenda_comida=" + $scope.configura.agenda_comida + "&dayw_one=" + $scope.configura.dayw_one + "&hour_ini_one=" + $scope.domingo_abre + "&hour_end_one=" + $scope.domingo_fecha + "&dayw_two=" + $scope.configura.dayw_two + "&hour_ini_two=" + $scope.segunda_abre + "&hour_end_two=" + $scope.segunda_fecha + "&dayw_three=" + $scope.configura.dayw_three + "&hour_ini_three=" + $scope.terca_abre + "&hour_end_three=" + $scope.terca_fecha + "&dayw_four=" + $scope.configura.dayw_four + "&hour_ini_four=" + $scope.quarta_abre + "&hour_end_four=" + $scope.quarta_fecha + "&dayw_five=" + $scope.configura.dayw_five + "&hour_ini_five=" + $scope.quinta_abre + "&hour_end_five=" + $scope.quinta_fecha + "&dayw_six=" + $scope.configura.dayw_six + "&hour_ini_six=" + $scope.sexta_abre + "&hour_end_six=" + $scope.sexta_fecha + "&dayw_seven=" + $scope.configura.dayw_seven + "&hour_ini_seven=" + $scope.sabado_abre + "&hour_end_seven=" + $scope.sabado_fecha + ""
        console.log(url);


        var encodedurl = encodeURI(url);

        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                var responseishere = xmlhttp.responseText;
                console.log(responseishere);
                var myobj = JSON.parse(responseishere);
                alert(myobj.message);
                $ionicLoading.hide();
            } else if (xmlhttp.readyState == 4 && xmlhttp.status != 200) {
                alert("Server Error");
                $ionicLoading.hide();

            }
        };
        xmlhttp.open("GET", "http://vovocooks.com.br/admin/apis/put/Configura_Vovo.php" + encodedurl, true);
        xmlhttp.send();

My PHP:

    <?php

header("Content-Type: text/html;  charset=uft-8",true); 
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");

    //formulário
    $data = file_get_contents("php://input");
    $objData = json_encode($data);


    // TRANSFORMA OS DADOS
    $cod_fornecedor = $_GET['cod_fornecedor'];
    $tem_delivery = $_GET['tem_delivery'];
    $custo_padrao = $_GET['custo_padrao'];
    $frete_gratis = $_GET['frete_gratis'];
    $valor_minimo_frete_gratis = $_GET['valor_minimo_frete_gratis'];
    $tipos_pagamentos = $_GET['tipos_pagamentos'];
    $prazo_entrega_min = date($_GET['prazo_entrega_min']);
    $prazo_entrega_max = date($_GET['prazo_entrega_max']);
    $agenda_comida = $_GET['agenda_comida'];
    $dayw_one = $_GET['dayw_one'];
    $hour_ini_one = date($_GET['hour_ini_one']);
    $hour_end_one = date($_GET['hour_end_one']);
    $dayw_two = $_GET['dayw_two'];
    $hour_ini_two = date($_GET['hour_ini_two']);
    $hour_end_two = date($_GET['hour_end_two']);
    $dayw_three = $_GET['dayw_three'];
    $hour_ini_three = date($_GET['hour_ini_three']);
    $hour_end_three = date($_GET['hour_end_three']);
    $dayw_four = $_GET['dayw_four'];
    $hour_ini_four = date($_GET['hour_ini_four']);
    $hour_end_four = date($_GET['hour_end_four']);
    $dayw_five = $_GET['dayw_five'];
    $hour_ini_five = date($_GET['hour_ini_five']);
    $hour_end_five = date($_GET['hour_end_five']);
    $dayw_six = $_GET['dayw_six'];
    $hour_ini_six = date($_GET['hour_ini_six']);
    $hour_end_six = date($_GET['hour_end_six']);
    $dayw_seven = $_GET['dayw_seven'];
    $hour_ini_seven = date($_GET['hour_ini_seven']);
    $hour_end_seven = date($_GET['hour_end_seven']);  


     // INSERE OS DADOS

    $db = new PDO("OS DADOS DE CONEXÃO DO BANCO DE DADOS AQUI...");


    if($db){

        $sql = "INSERT INTO fornecedor_configura_frete (cod_fornecedor,tem_delivery, custo_padrao, frete_gratis, valor_minimo_frete_gratis, tipos_pagamentos, prazo_entrega_min, prazo_entrega_max, agenda_comida, dayw_one, hour_ini_one, hour_end_one, dayw_two, hour_ini_two, hour_end_two, dayw_three, hour_ini_three, hour_end_three, dayw_four, hour_ini_four, hour_end_four, dayw_five, hour_ini_five, hour_end_five, dayw_six, hour_ini_six, hour_end_six, dayw_seven, hour_ini_seven, hour_end_seven) VALUES ('$cod_fornecedor', '$tem_delivery', '$custo_padrao', '$frete_gratis', '$valor_minimo_frete_gratis', '$tipos_pagamentos', '$prazo_entrega_min', '$prazo_entrega_max', '$agenda_comida', '$dayw_one', '$hour_ini_one', '$hour_end_one', '$dayw_two', '$hour_ini_two', '$hour_end_two', '$dayw_three', '$hour_ini_three', '$hour_end_three', '$dayw_four', '$hour_ini_four', '$hour_end_four', '$dayw_five', '$hour_ini_five', '$hour_end_five', '$dayw_six', '$hour_ini_six', '$hour_end_six', '$dayw_seven', '$hour_ini_seven', '$hour_end_seven')";


        $query = $db->prepare($sql);


        $query ->execute();


        echo json_encode(array('message'=> ' Os dados foram inseridos com sucesso. Obrigado e bem vindo!' ));
    }else{
        echo json_decode(array('message'=> ' Não foi possivel iserir os dados! Tente novamente mais tarde!' ));
    };


?>
    
asked by anonymous 25.03.2017 / 03:25

2 answers

0

Personally I decided to do this in my PHP using utf8_decode:

 <?php

header("Content-Type: text/html;  charset=uft-8",true); 
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");

    //formulário
    $data = file_get_contents("php://input");
    $objData = json_encode($data);

    $_REQUEST = array_map(utf8_decode, $_REQUEST);


    // TRANSFORMA OS DADOS
    $cod_fornecedor = $_GET['cod_fornecedor'];
    $tem_delivery = utf8_decode($_GET['tem_delivery']);
    $custo_padrao = $_GET['custo_padrao'];
    $frete_gratis = utf8_decode($_GET['frete_gratis']);
    $valor_minimo_frete_gratis = $_GET['valor_minimo_frete_gratis'];
    $tipos_pagamentos = utf8_decode($_GET['tipos_pagamentos']);
    $prazo_entrega_min = date($_GET['prazo_entrega_min']);
    $prazo_entrega_max = date($_GET['prazo_entrega_max']);
    $agenda_comida = utf8_decode($_GET['agenda_comida']);
    $dayw_one = $_GET['dayw_one'];
    $hour_ini_one = date($_GET['hour_ini_one']);
    $hour_end_one = date($_GET['hour_end_one']);
    $dayw_two = $_GET['dayw_two'];
    $hour_ini_two = date($_GET['hour_ini_two']);
    $hour_end_two = date($_GET['hour_end_two']);
    $dayw_three = $_GET['dayw_three'];
    $hour_ini_three = date($_GET['hour_ini_three']);
    $hour_end_three = date($_GET['hour_end_three']);
    $dayw_four = $_GET['dayw_four'];
    $hour_ini_four = date($_GET['hour_ini_four']);
    $hour_end_four = date($_GET['hour_end_four']);
    $dayw_five = $_GET['dayw_five'];
    $hour_ini_five = date($_GET['hour_ini_five']);
    $hour_end_five = date($_GET['hour_end_five']);
    $dayw_six = $_GET['dayw_six'];
    $hour_ini_six = date($_GET['hour_ini_six']);
    $hour_end_six = date($_GET['hour_end_six']);
    $dayw_seven = $_GET['dayw_seven'];
    $hour_ini_seven = date($_GET['hour_ini_seven']);
    $hour_end_seven = date($_GET['hour_end_seven']);  


     // INSERE OS DADOS

    $db = new PDO("mysql:DADOS DA CONEXÃO");


    if($db){

        $sql = "INSERT INTO fornecedor_configura_frete (cod_fornecedor,tem_delivery, custo_padrao, frete_gratis, valor_minimo_frete_gratis, tipos_pagamentos, prazo_entrega_min, prazo_entrega_max, agenda_comida, dayw_one, hour_ini_one, hour_end_one, dayw_two, hour_ini_two, hour_end_two, dayw_three, hour_ini_three, hour_end_three, dayw_four, hour_ini_four, hour_end_four, dayw_five, hour_ini_five, hour_end_five, dayw_six, hour_ini_six, hour_end_six, dayw_seven, hour_ini_seven, hour_end_seven) VALUES ('$cod_fornecedor', '$tem_delivery', '$custo_padrao', '$frete_gratis', '$valor_minimo_frete_gratis', '$tipos_pagamentos', '$prazo_entrega_min', '$prazo_entrega_max', '$agenda_comida', '$dayw_one', '$hour_ini_one', '$hour_end_one', '$dayw_two', '$hour_ini_two', '$hour_end_two', '$dayw_three', '$hour_ini_three', '$hour_end_three', '$dayw_four', '$hour_ini_four', '$hour_end_four', '$dayw_five', '$hour_ini_five', '$hour_end_five', '$dayw_six', '$hour_ini_six', '$hour_end_six', '$dayw_seven', '$hour_ini_seven', '$hour_end_seven')";


        $query = $db->prepare($sql);


        $query ->execute();


        echo json_encode(array('message'=> ' Os dados foram inseridos com sucesso. Obrigado e bem vindo!' ));
    }else{
        echo json_decode(array('message'=> ' Não foi possivel iserir os dados! Tente novamente mais tarde!' ));
    };


?>
    
25.03.2017 / 15:49
2

Check the bank's matching, it must be the same as the page. If the database has utf8, you can use the utf8_encode () php function.

    
25.03.2017 / 15:46