【问题标题】:PHP can't read email address from $http post method of angularPHP无法从角度的$http post方法读取电子邮件地址
【发布时间】:2016-11-24 13:28:17
【问题描述】:

除电子邮件地址外,一切正常。当我将电子邮件地址发布到服务器并回显它时,什么也没有收到。只有@符号有问题,其余都ok。

角度:

$http({
            method: 'POST',
            url: 'http://______.org/_____.php',
            data: {
                signInSubmitBTN: '',  email: 'joe@g.com'
            }
        }).success(function (data) {
            alert(data); //alert empty when joe@g.com but joeg.com is ok
        });

PHP

if (isset($_POST['signInSubmitBTN'])) {

$email = $_POST["email"];

echo $email;
}

注意 - 已配置应用程序

app.config(function ($httpProvider, $httpParamSerializerJQLikeProvider) {
    $httpProvider.defaults.transformRequest.unshift($httpParamSerializerJQLikeProvider.$get());
    $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8';
    })

【问题讨论】:

    标签: php angularjs


    【解决方案1】:

    你需要使用base64编码:

    signInSubmitBTN: '',  email: window.btoa('joe@g.com')
    

    别忘了在服务器端使用atob()进行解码

    【讨论】:

    【解决方案2】:

    在后端使用此代码在 PHP 中获取 POST 数据。

    if(isset($_POST)){
    
      $postdata = file_get_contents("php://input");
    
     $request = json_decode($postdata);
      echo $request->email;
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-08
      • 1970-01-01
      • 1970-01-01
      • 2011-03-27
      • 2013-09-15
      • 1970-01-01
      相关资源
      最近更新 更多