在Angularjs中使用$ post参数发送

时间:2014-07-15 18:45:41

标签: javascript angularjs http post

我尝试使用带有Angulars.js的$ http POST发送一个handontable表数据 以下代码:

 var $container = $("div#table");         
 var handsontable = $container.data('handsontable');
 $scope.saveData = function() {
                $http.post('save.php', {'data':handsontable.getData()}).success(function(res,status) {
                      if (res.result === 'ok') {
                        console.log('Data saved');
                      }
                      else {
                        console.log('Save error');
                      }
                });
 }

但我收到了“保存错误”#39;与

Undefined index: data in <b>C:\xampp\htdocs\angular\save.php

我是Chrome中的开发工具我获得此表单的请求有效内容:

{"data":[[fdf,gsgg,gsg,null,null,null],[sgsg,sgg,sgg,ggs,null,null]]}

我在$ http.post中更改了参数以使其工作但没有解决方案, 谢谢你提出一些建议!!!

1 个答案:

答案 0 :(得分:0)

我终于在这里找到了一个解决方案:[How to retrieve Request Payload

而不是以这种方式检索数据

$values=$_POST['data'];

我以这种方式取货:

$request_body = file_get_contents('php://input');
相关问题