如何用angular js发布数据到sql server

How to post data with angular js to sql server

本文关键字:数据 sql server angular 何用 js 布数据      更新时间:2023-09-26

感谢您的所有输入,但现在我或多或少有类似的问题,我有需要存储在sql-server数据库的数据,当我试图发布它的数据没有得到写。我的代码结构正确吗?

self.CurrentDowntimeEvent = {
        method: 'POST'
        , url: 'someurl/test'
        , data: {
          DepartmentId: cookie
        , CategoryId: -1
        , Comment: ""
        , DowntimeStart: "2014-07-07T10:00:00"
        , DowntimeEnd: null
        }
        , headers: {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'}
    }).success(function (data) {
        console.log(data);
    }).error(function (data) {
    });

$http是一个应该被注入到控制器的服务,所以你不应该需要self.来引用它:

self.RecordsSave = function () {
    for (var i = 0; i < self.Employees.length; i++) {
        var employee = self.Employees[i];
        var params = {
            CompanyNumber: employee.ClockNumber,
            Department: employee.DepartmentID,
            Present: employee.Present,
            Reason: employee.AbsentCode
        };
        $http.post(SAVE_EMPLOYEERECORDS, {
            params: params
        }).success(function (data) {
            alert("testing");
        });
    }
};