AngularJS http没有正确发送数据

时间:2015-08-11 09:15:16

标签: php angularjs

AngularJS $ http.post()没有像我期望的那样发送数据。我尝试将一系列数据传递给存储在同一服务器上的PHP脚本,当我尝试回显时,数据似乎总是空的。

我的PHP脚本接收数据

<?php

$char = $_POST["char"];
$alpha = $_POST["alpha"];

echo $char;

我的JS发布到PHP脚本

.controller("IndexController", function($scope, $http) {
    $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";

    $http.post("http://jxxxxxxx.xxx/ui/php/curl/index.php", {
        char: "a", alpha: 1
    }).then(function(response) {
        console.log(response);
    });
});

在上面的例子中,响应应该包含一个包含$ char值的data属性,在本例中为“a”。

但是,如果我

echo "hey"; 

在PHP脚本之外,当我将响应记录到控制台时,它会将此作为数据属性接收。

知道为什么我的PHP脚本没有正确接收POST值吗?

0 个答案:

没有答案
相关问题