My problem is very common. I must be doing some silly mistake somewhere but I am not able to figure it out.

我的问题非常普遍。我必须在某处做一些愚蠢的错误,但我无法弄明白。

I am send my form data in serialized form but it is not coming to PHP at all.

我以序列化的形式发送我的表单数据,但它根本不是PHP。

Angular JS code:

Angular JS代码:

saveForm: function() {
    var str = $('#feedbackForm').serializeArray();
    alert(JSON.stringify(str)); // here I am getting my data properly
    return $http({
        method  :'POST',
        url:'http://localhost/api?module=form&app_id=APP001&action=save&formid=2&user_id=3',
        data: str
    });
}

PHP

$log->info($_REQUEST); // I am getting all GET parameters correctly

tried this also

也试过这个

$log->info($_POST);

it is not printing my data. why?

它不打印我的数据。为什么?

1 个解决方案

#1


2

By default, the $http will send the data as application/json, which won't be recognized by the $_POST in PHP.

默认情况下,$ http会将数据作为application / json发送,PHP中的$ _POST将无法识别这些数据。

You have to choose either sending the data as form data like this:

您必须选择将数据作为表单数据发送,如下所示:

return $http({
  method: 'POST',
  url: 'http://localhost/api?module=form&app_id=APP001&action=save&formid=2&user_id=3',
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
  data: str
});

Or don't use the $_POST but read and parse input directly in PHP like this:

或者不要使用$ _POST,而是直接在PHP中读取和解析输入,如下所示:

$rawInput = file_get_contents('php://input');
$data = json_decode($rawInput);

Hope this helps.

希望这可以帮助。

更多相关文章

  1. 在Servlet和HTML页面之间处理函数调用和数据传输的最佳方法是什
  2. 访问D3的var格式数据
  3. HTML/JS作为本地SQLite数据库的接口
  4. 如何使用条件if()使用javascript检索带有指定值的选择标记的xml数
  5. 使用Object.observe 实现数据绑定
  6. 环回 - 在“保存后”挂钩中覆盖之前查看数据
  7. 基于缓冲区数据创建文件
  8. 怎么javascript读取本地文件中的数据,并显示在html上
  9. 使用异步库汇编数据库中的所有标记

随机推荐

  1. 关于android中的内部存储与外部存储
  2. Android相对布局实现各种梅花效果
  3. Android 并发之Handler、Looper、Message
  4. 如何在Android上安装apk软件
  5. 5、frida进阶-Android逆向之旅---Hook神
  6. 常用知识篇 一 Selector state状态对应说
  7. 二十四、Android文件的读写
  8. Android开发之获取手机网络状态及网络是
  9. [Android] TextView只显示一行,多余显示
  10. android 绘图时抗锯齿方法两种