I have a simple resource like.
angular.module('app').factory('nmCategory', function($resource){
var categoryResource = $resource('/api/categories/:id',{id:"#id"}, {
update: {method: 'PUT', isArray : false},
get: {method: 'GET' },
});
return categoryResource;
});
When I called nmCategory.query(), i get all the result returned. However, i am trying to filter by id. Thats to the a single record ehre id is #id. I then try nmCategory.get({id: 1}); and to my surprise, it fails and returning
/api/categories/1 Not found (404)
I was expecting to get my single record my id . I searched through more examples online, yet none refute what i am doing. Please how do i achieve this? Any help would be appreciated.
Navigate to that URL in your browser and see if it works. It probably doesn't. This is most likely a back-end issue, not an Angular issue.
Related
I have a quite basic $resource call :
getActiveListUsers = function(departmentId){
var activeUsersList = $resource("rest/users/active", {}, {
'getActiveUsersList': {method: 'GET', isArray: true, cache : true}
});
return activeUsersList.getActiveUsersList(
{departmentId: departmentId}
);
}
Though, when I look through network calls, I see that the same request is always called, and when I look at the 'cache' part of the request, I see it is fetched every time.
I am surely doing it the wrong way (or understanding it the wrong way!)... thus, any tip is welcomed here!
Thanks in advance!
Angular version : 1.2.16 (cannot be upgraded)
Look at this article it might help you to use $resource cache in a much better manner...
http://blog.aliasapps.com/caching-get-requests-using-angular-resource/
I have a problem in getting list of users using $resource.
I am making a webservice call using $resource to get list of users. It works most of the time, but when ever the response takes some time I am getting 500 internal server error.
The code I am using to call the webservice:
$resource("user/referral/getUserList", {}, {
query: {
method: 'GET'
}
})
I will be grateful for your help.
It looks like you are missing a "/" at the left.
user/referral/getUserList
Please keep this as well if you want to have the result as an array.
'query': {method:'GET', isArray:true}
I had the same problem in Glassfish.
It's a bug in Glassfish 4.1.1 https://java.net/jira/browse/JERSEY-2888
I was able to fix it in this way:
In glassfish/modules/org.eclipse.persistence.moxy.jar fix META-INF/MANIFEST.MF Just append the following to Import-Package:
,org.xml.sax.helpers,javax.xml.parsers;resolution:=optional,javax.naming;resolution:=optional
in 72 line and restart GF
I'm trying to mock a $http get request with parameters. Using the actual $http service we could do something like this
$http.get(url, {params : { articleId:10, id : 1}})
.success(function (response) {
defer.resolve(response.data);
});
Can we do the same with $httpBacked?
$httpBackend.when('GET', url, { params: { articleId: 10, id : 1}})
.respond({data: areas});
The obvious unpleasant alternative is writing out the full expected url which I am hoping I don't have to do as this feels neater.
Thanks
I had forgotten about this question, unfortunately the answer is that you have to specify the full get url with parameters
....just incase someone stumbles across this with the same problem
Apparently the only thing that can be passed parameters in a regular expression. According to the documentation of angular only four parameters can be passed, method, url, data, and headers.
I'm trying to learn AngularJS starting with that example: http://jsfiddle.net/mjaric/pJ5BR/
but when I tried to download in localhost, not works. I think that is a URL problem in /echo/json':
$scope.loadPeople = function() {
var httpRequest = $http({
method: 'POST',
url: '/echo/json/',
data: mockDataForThisTest
}).success(function(data, status) {
$scope.people = data;
});
};
But I don't know how to solve it. Any idea or hint?
My finally idea is load json from a search petition. It's possible that 'data' will be charged from web or online.
The url: '/echo/json/' is a feature of JsFiddle. If you look at the tabs to the left, in Ajax Requests you can see the usage. It probably won't work with this url in localhost.
You need to create a web project, where you can send your request. You could send some search parameters from client side, then filter the data with those parameters in the server and then return the filtered data to show.
The following article will give you some good ideas
http://tutorials.jenkov.com/angularjs/ajax.html
This link provides a hands on example by a really good tutor.
http://weblogs.asp.net/dwahlin/learning-angularjs-by-example-the-customer-manager-application
I'm trying to delete a model on my backend and what I do is this (the code is adapted just to show you the issue, some parts could be missing):
attending= new Backbone.Model();
attending.url= this.url() + "/reject";
attending.set({
id: this.id
})
attending.destroy({
success: function(){
alert("yes");
},
error: function(){
alert("no");
}
});
but what I always obtain is a "no" alert. The fact is the backend seems to be updated correctly and what I obtain as a response too. Here it is:
so... what's wrong with the response I get? Why doesn't backbone recognizes it as a successful response? I get 200/OK and a "application/json" format as well!
Your backend should return something with 200
jQuery expect 200 with application/json to have some content
Have a look here: https://github.com/jashkenas/backbone/issues/2218#issuecomment-20991938
You might want to place a "debugger;" in the error callback and trace exactly why its coming that route vs the success route. That should atleast get your started on the right path...