无法将json值从angularjs发布到php
Not able to post json value from angularjs to php
我已经用angular编写了一个服务,将值发布到PHP页面。它看起来像这样:
postValues: function(id,userImg) {
return $http({
method: 'post',
url: 'phppage.php',
data: { id: 1,number: 3 },
dataType: 'json',
headers: {'Content-Type': 'application/json'}
});
}
我的PHP代码看起来像这样。
$id=$_POST['id'];
$no=$_POST['number'];
但我得到了未定义的索引错误。
然后我尝试了另一种方法:
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$id = $request->id;
$number = $request->number;
但这也没有产生任何结果。
可能的原因是什么?这不是将值从angular POST到PHP的正确方法吗。
p.S:我还尝试过使用jQuery的$.praram()。
尝试发送这样的http请求,并使用promise捕获工厂函数中的响应
postValues: function(id,userImg){
$http({
method: 'POST',
url: 'phppage.php',
data: { id: 1,number: 3 },
headers: {'Content-Type': 'application/json'}
}).then(function(response){
return response
},function(response){
return response
})
}
相关文章:
- AngularJS JSON not arriving php
- AngularJS+PHP.登录面板
- 无法将json值从angularjs发布到php
- 将php表转换为angularjs javascript方法
- 使用AngularJs,尝试通过Google App Engine上的PHP使用HTML联系我们表单发送电子邮件
- AngularJS工厂调用PHP,然后返回AngularJS
- 如何使用Angularjs以PHP方式提交表单
- Angularjs-使用php上传文件
- 我可以't使用AngularJS读取用PHP创建的Cookie
- AngularJS:在ng-reeat中从php输出数组(带键)
- Angularjs和服务器端返回值(PHP)
- AngularJS将对象作为PHP的数组发送
- AngularJS无法从PHP获取HTTP标头
- 动态路由PHP&AngularJS
- 将JSON从PHP控制器传递到AngularJS控制器的最佳方式
- 如何处理php(Laravel-api)和javascript(AngularJS)之间的日期时间
- AngularJS与我的PHP API:获得值的工厂(async:false need alternative)
- Json 数据不会显示在使用 php 文件的 angularjs 中的 html 文件中
- 我无法通过 POST 方法从 angularjs 向 php 发送请求
- 奇怪的行为 AngularJS & PHP