Get Count of Rows via https request - angularjs

i get the data for my table via $http request like this:
$http.post('/DesktopModules/MyServices/API/PService/LoadPObjectListData', request).
success(function (data, status, headers, config) {
....
My question is, how can i display the value of loaded rows while the request pending?

I think it's not possible , while the request pending. But you can do it whild the request succeed.
html
<span>{{DataCount}}</span>
and js side
$http.post('/DesktopModules/MyServices/API/PService/LoadPObjectListData', request)
.success(function (data, status, headers, config) {
$scope.DataCount=data.length
}

Related

AngularJs $http timeout response code

If I have
$http.get(url)
.success(function(data, status, headers, config) {})
.error(function(data, status, headers, config) {});
what value would status have if ther were a timeout (no internet connection). Would it just be 404?
Sicne #HamletHakobyan won't post an answer, I will point out that his comment was correct - status is -1

Retrieve $http error status

I use Angular $http GET request that respond with 401 status, as i verified with Chrome network tab.
Inside the errorCallback for this request the response.status is always -1. When i started to investigate it i found the source of -1 deeply inside angular file:
var requestError = function() {
// The response is always empty
// See https://xhr.spec.whatwg.org/#request-error-steps and https://fetch.spec.whatwg.org/#concept-network-error
completeRequest(callback, -1, null, null, '');
};
So, how i can retrieve the status code?
Call it like this:
$http.get('/Url').
success(function(data, status, headers, config) {
}).
error(function(data, status, headers, config) {
});
Finally i found the reason is CROS error. when i changed API endpoint to responde with header: Access-Control-Allow-Origin:* the problem solved and i can see the status code.

Sending data from form to POST request in Angular

I want to make a POST request using Angular. I am using ng-submit to submit the form to the controller where I access the factory to make the request using:
$http.post('/droplets', data)
I need the data from the form fields to put in the "data" variable above to send to my API but I can't work out how to do this when it is more than one field. How is this done?
Try this...
$http({
url: '/droplets',
method: "POST",
data: JSON.stringify({application:app, from:data1, to:data2}),
headers: {'Content-Type': 'application/json'}
}).success(function (data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
}).error(function (data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
};
Ref:https://docs.angularjs.org/api/ng/service/$http

JSONP $http request to Dreamfactory returns server error

I am trying to access the dreamfactory data through $http request. To handle cross domain request, i have just added the JSON callback with the url.
.factory('DonorService', ['$resource','$http', '$q',
function($resource,$http,$q){
return{
getDonors:function(){
var donor = "https://dsp-sixerofsixes.cloud.dreamfactory.com/rest/db/icbd_donors/?callback=JSON_CALLBACK&app_name=blooddonate&fields=*";
var deferred = $q.defer();
$http.jsonp(donor).
success(function(data, status, headers, config) {
console.log(data);
deferred.resolve(data);
}).
error(function(data, status, headers, config) {
console.log(data);
});
return deferred.promise;
}
}
}])
But on making the request it creates a internal server error in the df. while typing the url in the browser shows the data along with wrapping callback.
Link to the JSON data
Link which is actually called from JSONP
I can't comment yet, so I guess I'll have to write this here.
Remove the resource injection. Just use $http.
ngResource incrementally creates those angular callback names.

Cross Domain request returns status code 0 in Firefox but 200 in Chrome

I have code in a directive that is making a cross domain request. When it runs in Chrome, it works just fine. When it runs in Firefox or IE 11, I get a status code of 0 with no data. My code is:
$http({method: 'GET', url: 'https://mycrossdomain.url'})
.success(function(data, status, headers, config) {
alert('success');
})
.error(function(data, status, headers, config) {
alert('error');
})
In Firefox and IE I get "error" alerted and in Chrome I get "success" and I can view the data.
Why would this be happening? The server obviously supports cross domain requests because it works in Chrome. When I navigate to the URL in all browsers I get a response so it definitely exists. Any help would be appreciated.
Turns out the issue was that I needed to specify withCredentials like so:
$http.get('https://mycrossdomain.url', { withCredentials: true})
.success(function(data, status, headers, config) {
alert('success');
})
.error(function(data, status, headers, config) {
alert('error');
})
This is because I needed to pass the user credentials (a certificate) to the other domain. Angular was unfortunately not providing very useful error messages.

Resources