【发布时间】:2017-05-06 17:40:57
【问题描述】:
我遇到了 angular ajax 请求的奇怪问题。 基本上我通过角度http请求将两个数据发送到php文件。 这是代码。
var allData={'city_id': city, 'uid': uid}
$http({
method : 'POST',
url : 'update_exec.php',
data : allData,
// headers : { 'Content-Type': 'application/x-www-form-urlencoded' } // set the headers
headers: {'Content-type': 'application/json'}
})
这是 php 文件。
$uid = $_POST['uid'];
$city = $_POST['city_id'];
echo $uid;
echo $city;
var_dump($_POST);
var_dump 的输出为空白。
当我签入萤火虫时,我在 XHR 中得到以下详细信息。 状态 -200 方法 - 选项 但参数中没有数据。
如果我将标题更改为 { 'Content-Type': 'application/x-www-form-urlencoded' } 这个。
然后我得到 Status - 200 和 Method - POST 我也可以在参数中看到数据。
但是对于这两种情况,我们都不会在 php 文件中输入数据。
【问题讨论】:
-
angular & api 是在同一个域还是不同的域?
-
它们在同一个域中。对于获取请求,它工作正常。
-
你可以试试打印
var_dump( file_get_contents('php://input')); -
var_dump(file_get_contents('php://input')); 没有输出。
-
NULL正在显示在var_dump上?