0

I am a starter in angularjs , am trying to do a log in form ,when user submits the form i am connection to a REST API url

http://XXX/XXX/index.php/report/login/format/json

when configuiring the url in PostMan rest client it works fine.!

But while configuring this url in angularjs as shown below and registering as a service

 User = $resource('http://xxx/xxx/index.php/report/login/format/json',{},
 {
   query: { method: 'GET', isArray: true },
   create: { method: 'POST' }
  });
User.create({email: user.email,password: user.password});

also tried enabling CORS in server side of no use.

i get a 404 error and values are not posted.

Any help will be much appreciated

1 Answer 1

0

I had the same issue. AngularJS put the post's data in the body of the request. Sometimes, the server can't find these post datas. For example, data didn't appear in the $_POST[] variable. That's why it works with Postman. To verify what is really sent in your request, I advise you to use Chrome tools. My solution was to change the getting of data on the webservice.

Here is the topic : post data - ngResource AngularJS

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

3 Comments

By looking at his resource I don't see why angular should put stuff in the body. The attributes from the first object passed to create should end up in the request URI as query parameters (.../format/json/?email=...), and not in the body.
When you make a POST request, parameters doesn't appear in the URI. Parameters appear in the URI just when you make a GET request. w3schools.com/tags/ref_httpmethods.asp
Right, I was forgetting it is a POST and not a GET.

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.