如何使用laravel中的angularjs从视图中获取表单数据?

时间:2018-06-15 10:20:53

标签: php angularjs laravel

我是laravel和angularjs的新手。我想将angularjs与laravel集成。我想用名称,电子邮件,密码,个人资料图片等字段制作注册表。我想使用angularjs将该表单提交给laravel控制器以在db中存储数据。我使用下面的代码将表单数据传递给控制器​​。

$http({
        method: 'POST',
        url: url,
        data: $scope.employees,
        headers: {'Content-Type': undefined}
    }).success(function (response) {
        console.log(response);
    }).error(function (response) {
        console.log(response);
        alert('This is embarassing. An error has occured. Please check the log for details');
    });

任何人都可以指导我如何从表格中获取所有数据,包括图像文件和其他字段。我也尝试使用FormData()传递表单数据,但在这种情况下我只获取图像文件。

1 个答案:

答案 0 :(得分:0)

最好的解决方案是将数据编码为json,然后在服务器端检索并解码。还要确保请求具有json内容类型。

相关问题