Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 角度http post,错误数据为空_Php_Angularjs - Fatal编程技术网

Php 角度http post,错误数据为空

Php 角度http post,错误数据为空,php,angularjs,Php,Angularjs,我正在尝试使用我的ionic应用程序将post数据发送到服务器脚本mail.php。 但是函数handleError中的'data'参数是null 你能帮我修一下吗 这可能是一个内容安全协议问题吗? 因为我不知道这里用什么。。。 我需要与boardlineapp.com进行沟通,并使用FB和谷歌单点登录 controllers.js: sendToServer.f(data).success(handleSuccess).error(handleError); function hand

我正在尝试使用我的ionic应用程序将post数据发送到服务器脚本
mail.php
。 但是函数
handleError
中的'data'参数是
null

你能帮我修一下吗

这可能是一个内容安全协议问题吗? 因为我不知道这里用什么。。。 我需要与boardlineapp.com进行沟通,并使用FB和谷歌单点登录

controllers.js:

  sendToServer.f(data).success(handleSuccess).error(handleError);
  function handleSuccess(data , textStatus, jqXHR ) {
      console.log("Message successfully sent");
      $("#mypanel").panel( "close" );
  }
  function handleError(data , textStatus, jqXHR  ) {
      console.log("Error when sending the message : ");
      console.log(data);
      console.log(data.response);
      console.log(textStatus);
      console.log(jqXHR);
      alert("The message could not be sent. Sorry for the inconvenience.");
  };
services.js:

.service('sendToServer', function sendToServerFactory($http) {  
    this.f = function(dataToSend) {
        return $http({
            url: 'http://id:password@boardlineapp.com/app/mail.php',
            method: "POST",
            data: dataToSend
        });
    }
})
mail.php:

<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST");
header("Access-Control-Allow-Headers: *");
if($_POST) {
    $userEmail=$_POST['userEmail'];
    $subject=$_POST['subject'];
    $destEmail=$_POST['destEmail'];
    $body=$_POST['body'];

    mail($destEmail, $subject, $body, "From:" . $userEmail);
#this bit doesn't work
#   $response = mail($destEmail, $subject, $body, "From:" . $userEmail);
#   echo $response;
#   exit();
}
?>
config.xml:

<access origin="*"/>
<allow-navigation href="*"/>
<allow-intent href="*"/>

在这方面,TypeError是一个转移视线的问题。真正给您带来问题的错误是访问控制允许源站问题。这是指向“*,*”服务器的错误配置,您不能复制相同的源,因此您必须更新配置(这取决于服务器的类型,例如nginx、apache、IIS等)

接下来,了解设置源策略的作用是一个好主意。这就是说,您允许通过以下方式访问服务器脚本:在本例中,您尝试加载两个不同的源boardlineapp.com和192.168.0.11:8100,这就是我假设您首先启用*的原因。这对于您的开发服务器来说是一个很好的解决方案,安全性可能不是一个大问题,但您希望在生产中更加具体


stackoverflow.com/q/19322973上的问答详细介绍了此问题的安全含义。

实际上,这似乎是一个跨站点来源安全(CORS)问题,请尝试为服务器配置正确的CORS标头,因为这样可以解决此问题或至少发现下一个问题。@PaulRyan我删除了这行
标头(“访问控制允许源代码:”)
在mail.php中,它现在似乎可以工作了。你能给我解释一下如何“为正确的CORS配置我的服务器”,因为我不知道怎么做。很抱歉,我是这方面的新手。很高兴这起作用,这里要记住的是,您允许或禁止来自多个来源(boardlineapp.com和192.168.0.11:8100)的脚本访问服务器上的内容。这在默认情况下是不允许的。通过启用CORS,您可以说您不关心这方面的安全性。这对于开发人员来说是可以的,但对于生产来说可能不是。您必须查看服务器的详细信息,了解如何正确配置(例如apache、nginx、IIS等)。关于这一点的含义的得体回答。
<access origin="*"/>
<allow-navigation href="*"/>
<allow-intent href="*"/>