Hello,

I am using angularjs for saving data in my DB.
But problem is it is inserting 2 rows in DB(SQL Server) as i think the 
controller is invoking 2 time on single click of submit button 

Also when i and putting an alert('test') as shown above then i am getting this 
alert twice.

HTML Page Code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml"; ng-app>
<head>
    <title></title>
    <link 
href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css";
        rel="stylesheet" type="text/css" />
    <script src="Scripts/angular.js" type="text/javascript"></script>
    <script src="Scripts/angular.min.js" type="text/javascript"></script>
    <script type="text/javascript">

        function saveCtrl($scope, $http) {
                alert('test');
            $scope.save = function () {
                $http({
                    contentType: "application/json; charset=utf-8",
                    url: 'WebService.asmx/InsertMethod',
                    method: "POST",
                    dataType: "json",
                    data: "{'Name':'" + $scope.UserName + "','Email':'" + 
$scope.Email + "'}", async: false,
                    success: function (response) {
                        $('#txtUserName').val('');
                        $('#txtEmail').val('');
                        alert("Record Has been Saved in Database");
                    },
                    error: function ()
                    { console.log('there is some error'); }
                });
            };
        };  

          
  
    </script>
</head>
<body>
    <div>
        <form id="form1" ng-controller="saveCtrl" ng-submit="save()">
        <div class="demo">
            <div class="ui-widget">
                <label for="tbAuto">
                    
                    Enter UserName:
                </label>
                <input type="text" id="txtUserName" ng-model="UserName" />
                &nbsp;
                <br />
                <br />
                Email:
                <input type="text" id="txtEmail" ng-model="Email" />
                <br />
                <br />
                <input type="submit" id="btnSubmit" value="submit" />
            </div>
        </div>
        </form>
    </div>
</body>
</html>


In order to insert in my db i use the following weservice code :

 Public Function InsertMethod(ByVal Name As String, ByVal Email As String) As 
String
        'List<string> result = new List<string>();
        Dim con As OleDbConnection = New OleDbConnection(conString)
        Dim cmd As OleDbCommand
        openConnection(con)
        cmd = con.CreateCommand()
        cmd.CommandText = "Insert into SampleTable (FirstName,LastName) 
values('" & Name & "', '" & Email & "')"
        cmd.ExecuteNonQuery()
        closeConnection(con)
        Return "True"
    End Function



Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to