i am making simple http request to doGet method of servlet to fetch data from table. bellow is my code.
var myApp = angular.module('myApp', []);
myApp.controller('myController', function ($scope,$http) {
$scope.getDataFromServer = function() {
$http
({
method:'GET',
url:'jasoncontroller'
}).success(function(data, status, headers, config){
$scope.sqldata = data;
console.log("executing");
$scope.$watch('sqldata',function(newValue,oldValue){
console.info('changed');
console.log('new : ' + newValue);
console.log('old : ' + oldValue);
console.log('watch end');
});
}).error(function(data, status, headers, config){});
};
});
servlet doGet method
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("Executing get");
getSqlData sql = new getSqlData();
Gson gson = new GsonBuilder().serializeNulls().create();
String tabname="saleq315";
String json = gson.toJson(sql.gettabledata(tabname));
response.setContentType("application/json");
response.getWriter().write(json);
System.out.println("data sent");
}
Whenever i click to fetch data it never get me new data once i change the table name in tabname="saleq315"; after multiple click table data refresh. and when i log this to console i see http request getting executed mulpliple times. If you see the image attached, i changed the table name and click to get the data,
first click - same table data --> console log one entry
seconds click - same table data --> console log one entry
third click - got new data --> console log 5 entries.
Not sure what is happening here.
[![enter image description here][1]][1]