我的数据没有发布到AngularJS的服务器中

时间:2019-02-21 22:00:31

标签: javascript asp.net angularjs

我已经添加了所有需要的脚本。服务位于asp.net中,我也在 web.config 文件中添加了HTTP POST方法。

HTML表单:

   <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
        <script src="Scripts/angular.js"></script>
        <script src="Scripts/InsertSession.js"></script>
    </head>
    <body ng-app="myModule1">
        <div ng-controller="mycontroller1">
            <form class="form-horizontal style-form" name="myform" >
                <div class="form-group">
                    <label class="col-sm-2 col-sm-2 control-label">Event Title </label>
                    <div class="col-sm-10">
                        <input type="text" id="title" name="title" class="form-control" ng-model="title1">
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label col-md-3">Date of Event </label>
                    <div class="col-md-4">
                        <input class="form-control" type="date" id="eventdate" name="eventdate" ng-model="eventdate">
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label col-md-3">Time of Event </label>
                    <div class="col-md-4">
                        <input class="form-control" type="time" id="eventtime" name="eventtime" ng-model="eventtime">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 col-sm-2 control-label">Event Location</label>
                    <div class="col-sm-10">
                        <input type="text" id="location" name="location" class="form-control" ng-model="eventlocation1">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 col-sm-2 control-label">Event description</label>
                    <div class="col-sm-10">
                        <input type="text" id="description" name=" description" class="form-control" ng-model="description1">
                    </div>
                </div>
                <div>
                    <button class="btn btn-theme btn-block" value="Create Event" ng-click="registereventdata()"> Submit </button>
                </div>
            </form>
            <!--ng-click="registereventdata()"   , ng-click="Insert(formdata)" ,type="submit"-->
        </div>
    </body>
    </html>

AngularJS代码:

var myapp = angular.module('myModule1', []);
myapp.controller("mycontroller1", function ($scope, $http,$window) {


    $scope.registereventdata = function () {

        $http({
            method: 'POST',
            url: 'WebService1.asmx/InsertSessionData',
            headers: {
                'content-type': 'application/json; charset=utf-8',
                'datatype': 'json'
            },
            data: { Title: $scope.title1, Date: $scope.eventdate, Time: $scope.eventtime, Location: $scope.eventlocation1, Description: $scope.description1, CreatedDate: $scope.eventdate, Email: "xyz", IsActive: true, IsDelete: false }
        }).then(function (response) {
                if (response.data.d > 0) {
                    alert("event add successfully.");
                }
                else {
                    alert("opss!!!not register event..try again");
                }
            })
    }
});

0 个答案:

没有答案