【发布时间】:2017-05-19 22:40:56
【问题描述】:
单击按钮时,我正在调用方法 Getdata();但问题是第一次加载页面时,如果我单击按钮,则会收到“HTTP 错误”响应。但是如果我再次单击该按钮,则会显示成功响应。
HTML
<button type="submit" class="btn btn-primary form-inline inline-Magrin" ng-click="Getdata()">Search</button>
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");
});
}
【问题讨论】:
-
控制台中的错误不是针对
/scrap/Resultdata的请求。查看您的网络流量,看看当请求有效和无效时有什么区别。我猜你的一些$scope变量第一次没有初始化 -
试试
type="button"而不是type="submit" -
你在某个地方弄乱了你的 url,但不是在插入的代码中。
标签: javascript angularjs