php - angularjs post 提交中文乱码?

查看:171
本文介绍了php - angularjs post 提交中文乱码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

html:

<div  ng-controller="login_input">
    <form ng-submit="check_login()">
        <div ><a>用户名:</a></div><div ><input type="text" required ng-model="login.uname"/></div>
        <div ><a>密码:</a></div><div ><input type="password" required ng-model="login.upassword"/></div>
        <div ><a>验证码:</a></div><div ><input type="number" min="0" required ng-model="login.chkcode"/><img src="img.php"/></div>
{{login}}
        <button class="a_button" type="submit">登录</button>
    </form>
</div>
</body>
<script type="text/javascript" src="js/angular.min.js"></script>
<script>
    var app = angular.module('login', []);

    app.controller('login_input', function ($scope,$http) {
      $scope.check_login=function(){
          var aa  = {
              uname : $scope.login.uname,
              upassword:$scope.login.upassword,
              chkcode:$scope.login.chkcode
          }
         if($scope.login.uname&&$scope.login.upassword&&$scope.login.chkcode){
             $http({
                 method: 'POST',
                 url: 'login.php',
                 data: aa,
             })
                 .success(function(response){
                     console.log(response);
                 })
         }
      }
    });
</script>

php:

<?php
header('Content-type: text/html; charset=gb2312');
$params = json_decode(file_get_contents('php://input'), true);

require("cfg.php");
global $dbh;
$user_name= $params["uname"];
$user_password= $params["upassword"];
$user_chkcode= $params["chkcode"];
var_dump(is_register());
var_dump($user_name);
function is_register()
{
    global $dbh, $user_name, $user_password;
    $up = sha1($user_password);

    $sql = "select user from gggg";
    $sth = $dbh->prepare($sql);
    $sth->bindParam(':username', $user_name);
   // $sth->bindParam(':pwd', $up);
    $sth->execute();
    $rs = $sth->fetchAll(PDO::FETCH_ASSOC);

      return $rs;
}
?>

接收到的user_name是乱码,这里是需要设置post时的headers吗?应该如何设置。
出于各种原因,需要最大限度地兼容以前的系统,所以要用gb2312.

解决方案

可以贴下post请求的http信息吗,

应该可以接收的时候先用UTF-8接收,然后要存储或者与其他服务交互在服务端转成gb2312,使用iconv()

@黎明星刻 提供的博客文章 http://blog.csdn.net/vera_xue...

这篇关于php - angularjs post 提交中文乱码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆