0

I am trying to store form data into database through angularjs but it is not storing into the database. Don't know what I am doing wrong?

My html form

<form  id="challenge_form" class="row" >
            <input type="text" placeholder="Challenge Name" ng-model="challengeName" />
            <select class="btn-group form-control" id="sel1" ng-model="challengeType">
                <option>-- Select Activity Type --</option>
                <option value="running">Running</option>
                <option value="walking">Walking</option>
                <option value="cycling">Cycling</option>
            </select>
            <input type="date" placeholder="Start Date" ng-model="startDate" />
            <input type="date" placeholder="End Date" ng-model="endDate" />
            <input type="button" class="btn btn-theme" ng-click="newChallenge()" value="Decide Prize">
            <input type="button" class="btn btn-theme"  value="Cancel">

        </form>

My angularjs controller

app.controller("NewChallengesController", ["$http", "$scope", "authenticationSvc", function ($http, $scope, authenticationSvc) {
    //alert("hello, inside New Challenge Controller");

    var token = authenticationSvc.getUserInfo();
    var config = {
        headers: {
            'h5cAuthToken': token.accessToken,
            'Accept': 'application/json;odata=verbose'
        }

    };


    $scope.newChallenge = function () {
        var data = {
            "challengeName": $scope.challengeName,
            "selectedRewardId": "283081",
            "startDate": $scope.startDate,
            "endDate": $scope.endDate,
            "activityCategoryId": 51,
            "minParticipant": 0,
            "referredNumbers": "9876543213",
            "distance": 15.0,
            "challengeType": $scope.challengeType
        };

        $http.post("http://103.19.89.152:8080/ccp-services/userchallenge/create", data, config).then(function (response) {
            alert("challenge created successfully");
        });
    };

}]);

I am getting the alert "challenge created successfully" but data is not storing into the database. Any help is highly appreciated!!

2
  • Check whats happening in the server side. Also try to console the response. Commented Jul 8, 2016 at 10:24
  • Try putting a breakpoint in your service to which you are posting the data..Also check what response code its returning in the fiddler Commented Jul 8, 2016 at 10:28

1 Answer 1

1

For Example , Please verify this request mapping /ccp-services/userchallenge/create model variable might be in your model object name is totally different what you have created in angularjs. So please make sure the model variable name should be same name of UI model variable then only its bind the data and Process it.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @SakthiSureshAnand,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.