• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

angularjs post 提交中文乱码?

php 搞代码 3年前 (2022-01-23) 16次浏览 已收录 0个评论
文章目录[隐藏]

html:

<code><div>            <div>用户名:</div><div></div>        <div>密码:</div><div></div>        <div>验证码:</div><div></div>{{login}}        <button class="a_button" type="submit">登录</button>    </div><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></code>

php:

<code><?phpheader('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;}?></code>

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

本文来*源gaodai^.ma#com搞#代!码网
搞gaodaima代码

回复内容:

html:

<code><div>            <div>用户名:</div><div></div>        <div>密码:</div><div></div>        <div>验证码:</div><div></div>{{login}}        <button class="a_button" type="submit">登录</button>    </div><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></code>

php:

<code><?phpheader('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;}?></code>

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

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

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

@黎明星刻 提供的博客文章 http://blog.gaodaima.com/vera_xue&#8230;

我在php中使用如下代码解决了问题:
$params = json_decode(file_get_contents(‘php://input’), true);
require(“cfg.php”);
global $dbh;
$user_name = $params[“uname”];//utf-8
$user_name = iconv(“UTF-8”, “GB2312”, $user_name);


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:angularjs post 提交中文乱码?

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址