2

hi i am trying to insert a row in mi table but always obtain this problem:

POST URL/api/presentaciones/[object%20Object] 404 (Not Found)

Well I have a form and the ng-submit="savePresentacion" inthe controller:

.controller('newPresentacionController', function ($scope, Presentacion, Categoria) {
             $scope.categorias ={};
             var vm = this;
             var presentacionData = {};
             $scope.savePresentacion = function() {
                 presentacionData = {
                     nombre : $scope.nombre,
                     descripcion : $scope.descripcion,
                     tipo_presentacion : $scope.tipo_presentacion,
                     usuarios_id : $scope.usuarios_id,
                     categorias_id: $scope.categorias_id,
                     longitude: self.myMarker.position.lng(),
                     latitud: self.myMarker.position.lat(),
                     zoom: 13
                 };
                 Presentacion.crearPresentacion(presentacionData).success(function (datos) {

                 });
             };
}

in the presentacionService have this:

(function () {
    angular.module('presentacionService', [])
        .factory('Presentacion', function ($http) {
            var presentacionFactory = {};
            presentacionFactory.crearPresentacion = function(presenData) {
                console.log(presenData);
                return $http.post('/api/presentaciones/' + presenData);
            };
            return presentacionFactory;
        });
})();

after of this give the problem. I did the same with 2 tables more and dont have problem just have problem with this part.

2 Answers 2

6

[object Object] is how a JavaScript object is rendered by default. Your console.log(presenData) will similarly output [object Object].

Given that you define presenData as a JSON object, I'm guessing you want to pass that in its entirety in your POST.

Change this:

return $http.post('/api/presentaciones/' + presenData);

to this:

return $http.post('/api/presentaciones/', presenData);

Note the comma. This will pass the presenData JSON object as the body of the request.

I would also change the logging statement to be console.log(JSON.stringify(presenData)), which will render the JSON representation to the console.

Sign up to request clarification or add additional context in comments.

1 Comment

yeah now work thanks bro, really a don't see it. 2 days working I'm tired.
0

Your problem is that your presenData is an object. When you append it to the string like this: '/api/presentaciones/' + presenData

Javascript is converting the object to a string, which is represented by [object Object].

You need to determine which attribute on your presenData represents the endpoint you are trying to access. For example, if presenData had a .id, you would want to append the string with the .id parameter.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.