-1

I have search page , so user can search with firstname,lastname and email address. Whatever variable user passed to the factory i want to get the match result, so in below code if i pass one variable others are coming undefined, How to avoid this issue and use the get request ?

So far tried code...

main.html

<div class="row">
        <div class="col-md-12">
            <div class="col-md-3"> First / Last
                Name :
            </div>
            <div class="col-md-3">
                <input type="text" class="form-control" id="attestorFirstName" ng-model="attestorDTO.firstName" />
            </div>
            <div class="col-md-3">
                <input type="text" class="form-control" id="attestorLastName" ng-model="attestorDTO.lastName" />

            </div>
        </div>
    </div>
    <br>
    <div class="row">
        <div class="col-md-12">
            <div class="col-md-3"> Email Address :
            </div>
            <div class="col-md-6">
                <input type="text" class="form-control" id="attestorMail" ng-model="attestorDTO.emailId" />
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <button class="btn btn-default pull-right" type="button" ng-click="searchAttestor()">
                Search</button>
        </div>
    </div>
<div  kendo-grid="attestorSearch" options="attestorSearchOptions" k-rebind="getAttestorSearchResultGrid"></div>

main.Ctrl

  $scope.searchAttestor = function() {
    $scope.searchresult = '';
    $scope.attestorSearchOptions.dataSource = rcsaAssessmentService
          .getOwnerSearchGridDataSource(
                  $scope.attestorDTO.firstName,
                  $scope.attestorDTO.lastName,
                  $scope.attestorDTO.emailId,
                  $scope.attestorDTO.nbkId);
    $scope.getAttestorSearchResultGrid = new Date().getTime();
    console.log("getting the response");
    console.log($scope.attestorDTO.lastName);
};

mainFactory.js

getOwnerSearchGridDataSource : function(fName, lName,
                                mailId, nbkId) {
                            return new kendo.data.DataSource({
                                type : 'json',
                                transport : {
                                    read : function(options) {

                                        return $http.get(
                                                'app/assessment/rest/ownerList?firstName=' +
                                                        fName + '&lastName=' +
                                                         lName + '&emailId=' +
                                                         mailId + '&nbkId=' +
                                                         nbkId).success(
                                                function(data) {
                                                    options.success(data);
                                                });
                                    }

                                },
                                pageSize : 5,
                                schema : {
                                    model : {
                                        fields : {
                                            fullName : {
                                                editable : false
                                            },
                                            workEmailAddressText : {
                                                editable : false
                                            },
                                            stdId : {
                                                editable : false
                                            }
                                        }
                                    },

                                }
                            });
                        },
aftab
  • 535
  • 4
  • 13
  • 46
  • possible duplicate of [AngularJS passing data to $http.get request](http://stackoverflow.com/questions/13760070/angularjs-passing-data-to-http-get-request) – makeitmorehuman Jun 16 '15 at 18:25

1 Answers1

1

Just use $http.post instead of $http.get -

But feed it the url with the get parameters, like so:

 return $http.post('app/assessment/rest/ownerList?firstName=' +
                    fName + '&lastName=' +
                    lName + '&emailId=' +
                    mailId + '&nbkId=' +
                    nbkId,
                   { postDataKey1 : "Post Data Value1",
                     postDataKey2 : "Post Data Value2"
                   }).success(function(data) {
                                        options.success(data);
                                    });

https://docs.angularjs.org/api/ng/service/$http

rm-vanda
  • 3,122
  • 3
  • 23
  • 34
  • I am not sure if this approach will work i am also mapping data-source to grid once search successfully made... – aftab Jun 16 '15 at 18:36
  • Nope i tried your approach its throwing 500 i believe backend its expecting get method... if i debug when i call getOwnerSearchGridDataSource from controller only variable field i use that is showing the value but others are showing undefined that should not happend thats why its not getting the result, Any idea how to resolve this issue ? how can i send other variables as empty string ? – aftab Jun 16 '15 at 19:09