1
按鈕單擊我正在調用一個方法Getdata();但問題是第一次加載頁面時,如果我點擊按鈕,然後得到「HTTP錯誤」響應。但如果我再次點擊該按鈕,則會顯示成功響應。Angular 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'變量沒有在第一次初始化 – rob
嘗試'type =「button」'而不是'type =「submit」' – Jer
你搞亂了你的url,但不是在插入代碼。 – neptune