Site content disappears when placing accents

Asked

Viewed 41 times

0

Hi, I’m creating a dynamic website with ajax, but when in the database has an accent all the yet dynamic disappears. I’ve tried to put the <meta charset="utf-8"> in html file and also not solved.

Can someone help me?

AJAX structure:

$.ajax({
                url: 'http://127.0.0.1/IMMLogin/api/sys/api.php',
                type: 'post',
                dataType: 'xml',
                data: {
                    'proc': $('#ToProc').val(),
                    'user': $('#user').val(),
                    'pass': $('#pass').val(),
                    'key': key
                }
            }).done(function(data){
                var statusCode = data.getElementsByTagName("status")[0].childNodes[0].nodeValue;
                var txt = data.getElementsByTagName("text")[0].childNodes[0].nodeValue;
                if(statusCode == "user-is-blank"){
                    $("#error").css("display", "block");
                    $("#error-txt").text(txt);
                    $("#user").css("border", "1px solid #ff9e9e");
                    $("#pass").css("border", "");
                    $("#user").val("");
                    $("#btn").val("ENTRAR");
                }else if(statusCode == "pass-is-blank"){
                    $("#error").css("display", "block");
                    $("#error-txt").text(txt);
                    $("#user").css("border", "");
                    $("#pass").css("border", "1px solid #ff9e9e");
                    $("#pass").val("");
                    $("#btn").val("ENTRAR");
                }else if(statusCode == "datainvalid"){
                    $("#error").css("display", "block");
                    $("#error-txt").text(txt);
                    $("#user").css("border", "1px solid #ff9e9e");
                    $("#pass").css("border", "1px solid #ff9e9e");
                    $("#pass").val("");
                    $("#user").val("");
                    $("#btn").val("ENTRAR");        
                }
            });

PHP file:

}elseif(strcasecmp("login-auth", $_POST['proc']) == 0){
            $authkey = $_POST['key'];
            $objenterid = BD::conn()->prepare("SELECT * FROM `login_key` WHERE key_login = ?");
            $objenterid->execute(array($authkey));
            $resnterid = $objenterid->fetchObject();
            $enterid = $resnterid->id_enterprise;
            $getpmen = BD::conn()->prepare("SELECT * FROM `login_profiles` WHERE id_enterprise = ?");
            $getpmen->execute(array($enterid));
            $respmen = $getpmen->fetchObject();
            $userblank = $respmen->txtUserBlank;
            $passblank = $respmen->txtPassBlank;
            $datainvalid = $respmen->DataInvalid;
            $user = $_POST['user'];
            $pass = sha1(md5($_POST['pass']));
            if($user == ""){
                $xml = "<?xml version='1.0' encoding='UTF-8' ?>";
                $xml .= "<error>";
                $xml .= "<text>";
                $xml .= $userblank;
                $xml .= "</text>";  
                $xml .= "<status>";
                $xml .= "user-is-blank";
                $xml .= "</status>";                
                $xml .= "</error>";
                echo $xml;
            }elseif($pass == "67a74306b06d0c01624fe0d0249a570f4d093747"){
                $xml = "<?xml version='1.0' encoding='UTF-8' ?>";
                $xml .= "<error>";
                $xml .= "<text>";
                $xml .= $passblank;
                $xml .= "</text>";  
                $xml .= "<status>";
                $xml .= "pass-is-blank";
                $xml .= "</status>";        
                $xml .= "</error>";
                echo $xml;
            }else{
                $objuser = BD::conn()->prepare("SELECT * FROM `users_clients` WHERE user = ? AND pass = ? AND ativo = 1");
                $objuser->execute(array($user, $pass));
                if($objuser->rowCount() == 0){
                    $xml = "<?xml version='1.0' encoding='UTF-8' ?>";
                    $xml .= "<error>";
                    $xml .= "<text>";
                    $xml .= $datainvalid;
                    $xml .= "</text>";
                    $xml .= "<status>";
                    $xml .= "datainvalid";
                    $xml .= "</status>";        
                    $xml .= "</error>";
                    echo $xml;
                }else{
                    $xml = "<?xml version='1.0' encoding='UTF-8' ?>";
                    $xml .= "<ok>";
                    $xml .= "<text>";
                    $xml .= "ok";
                    $xml .= "</text>";
                    $xml .= "<status>";
                    $xml .= "ok";
                    $xml .= "</status>";    
                    $xml .= "</ok>";
                    echo $xml;
                }
            }
        }

HTML file:

<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <link rel="stylesheet" type="text/css" href="css/login.css">
        <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
        <script type="text/javascript" src="js/jquery.js"></script>
        <script type="text/javascript" src="js/login.js"></script>
    </head>
    <body>
    <div id="name">
    <p id="titulo"></p>
    </div>
    <div id="error">
    <p id="error-txt"></p>
    </div>
    <br />
    <br />
    <br />
    <br />
    <div id="login">
    <table>
    <form id="loginform">
        <tr>
            <td><img src="" id="logo" width="100" height="100"></td>
        </tr>
        <tr>
            <td id="txtUser"></td>
        </tr>
        <tr>
            <td id="txtPass"></td>
        </tr>
        <tr>
            <td><br /><input type="submit" name="btn" id="btn"></td>
        </tr>
        <tr>
            <td><br /><br /><br /><a href="" id="sair"></a></td>
        </tr>
        <input type="hidden" name="ToProc" id="ToProc" value="login-auth">
    </form>
    </table>
    </div>
    </body>
    </html>

1 answer

1


Tries to place the external js file call with utf-8

 <script type="text/javascript" src="*.js" charset="utf-8"></script>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.