[英]Angular HTTP does not work on first click
On button click I am invoking a method Getdata(); 在按钮上单击我正在调用方法Getdata(); but the problem is when the page is loaded for the first time, if I click on the button then I get "HTTP error" response.
但是问题是第一次加载页面时,如果单击按钮,则会收到“ HTTP错误”响应。 but if I click on the button again then it shows success response.
但是如果我再次单击该按钮,那么它将显示成功响应。
HTML HTML
<button type="submit" class="btn btn-primary form-inline inline-Magrin" ng-click="Getdata()">Search</button>
JS JS
$scope.Getdata = function () {
if (($scope.NumberOfrecords > $scope.TotalRecords) && ($scope.TotalRecords != 0)) {
alert("Search record count should not be greater than total records");
return;
}
debugger;
$http({
url: '/scrap/Resultdata',
method: "GET",
params: {
Searchbox: $scope.Searchbox,
Category: $scope.Category,
NumberOfrecords: $scope.NumberOfrecords
}
}).then(
function successCallback(response) {
response = $scope.filterRecord(response);
debugger;
$scope.data = response.data.ResponseItems;
$scope.TotalRecords = response.data.TotalResults;
$scope.tableParams = new NgTableParams({
page: 1,
count: 10
}, {
data: $scope.data
});
},
function errorCallback(response) {
debugger;
alert("error");
});
}
按钮类型为“提交”,应为“按钮”
<button type="button" class="btn btn-primary form-inline inline-Magrin" ng-click="Getdata()">Search</button>
if you are having the submit as type, then you need to add the tags in the html, 如果您使用的是提交类型,则需要在html中添加标签,
and in form -------- OnSubmit=GetData() 并以-------- OnSubmit = GetData()的形式
Please try using type=button instead 请尝试改用type = button
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.