This is a migrated thread and some comments may be shown as answers.

Double $http.post server calls

2 Answers 139 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Irmantas
Top achievements
Rank 1
Irmantas asked on 09 Mar 2017, 10:16 PM

I am working on a search page where search results will get displayed in a grid. I have a search button that will trigger the to execute http call to the server to retrieve the data. However, only when for the first time search button clicked request gets sent once, every subsequent click two requests are being sent. I am out of ideas what is causing this.
Here is the code that gets executed once each time search button is clicked:

$scope.gridData = new kendo.data.DataSource({ transport: { read: function (e) { $http.post('/Provider/ProviderSearchResult', angular.toJson(dataTransferObject)) .then(function success(response) { e.success(response.data); console.log("success: " + response.data); }, function error(response) { alert('something went wrong') console.log("error: " + response); }) }, }, pageSize: 10, sort: { field: "rating", dir: "desc" }, });

Any help would be appreciated. Thank you.

2 Answers, 1 is accepted

Sort by
0
Irmantas
Top achievements
Rank 1
answered on 09 Mar 2017, 10:24 PM

Apologies for posting inline code. Here is more readable version of the above:

$scope.gridData = new kendo.data.DataSource({
                transport: {
                    read: function (e) {
                        $http.post('/Provider/ProviderSearchResult', angular.toJson(dataTransferObject))
                        .then(function success(response) {
                            e.success(response.data);
                            console.log("success: " + response.data);
                        }, function error(response) {
                            alert('something went wrong')
                            console.log("error: " + response);
                        })
                    },
                },
                pageSize: 10,
                sort: { field: "rating", dir: "desc" },
            });

0
Irmantas
Top achievements
Rank 1
answered on 10 Mar 2017, 02:39 PM
Resolved by moving $http.post request code directly into click button event handler.
Tags
Grid
Asked by
Irmantas
Top achievements
Rank 1
Answers by
Irmantas
Top achievements
Rank 1
Share this question
or