Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I created a simple submit page using codeigniter and angular.js. How can I throw HTTP status codes after somebody clicked submit button, so the the user will know if it is successful or not, or any other reason why it failed?

BTW, I base my code in this post Codeigniter + Angular Js: How to receive JSON data

share|improve this question
    
If it came to success callback, then it is succesful, if it come to error is not? Why do you want to know HTTP status code. For that you have to use then. –  Chandermani Sep 12 at 8:31

1 Answer 1

Don't use .success() IMHO. Use .then() instead.

.then(function(resp){
    var $status = resp.status //http status code
    var $data = resp.data //data back from the server
});

If you're set on using success, then check out all the arguments for the success function:

success(function(data, status, headers, config)

As usual, check the docs when you'er in doubt

share|improve this answer
    
do I need to do something in my controller where the data is submitted? Like sending HTTP code? –  Port 8080 Sep 12 at 8:27
    
Explain why he should use then() instead of success()! –  bad_boy Sep 12 at 8:28
    
.then() is not working. –  Port 8080 Sep 12 at 8:29
    
The status in the above indicates the response from the server, Here's a list of those codes. You can return your own response with custom text by simply returning a json encoded array, as such: echo json_encode(array('status' => 'OK', 'msg' => 'it went ok!'));. Then in your angular you can access this like: resp.data.status –  Ohgodwhy Sep 12 at 8:29
    
The reason I say to use .then() instead of .success() is due to the fact that a promise is returned from the $http call which can allow you to chain methods against it. In this particular case, it's a non issue, but in practice, it will be better as you'll be used to it for more complex tasks. –  Ohgodwhy Sep 12 at 8:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.