Returning successful/failed AJAX responses, and HTTP-status codes -


Assuming I have a stack overflow-esque site, I want to post a comment below someone's answer, two things :

1) The comment post is successful. I return the original formatted DIV as some JSON response, I set the JSON. {/ Code>

2) The comment post is unsuccessful.

I return the error as a JSON response.

  {"success": incorrect, "data": "you can only post every 15 seconds"}  

Does this work correct The way? I notice that the stack overflow is returning the Apache <500> internal error code when a comment post fails, which is messing me up.

This is a 500 internal error reserved for things that are incorrect with the actually server, just because some comment validation fails No?

I agree that using 500 internal error is a bit weird, But there is also a number of response codes that you can use to meet your needs.

Here's a good list:

Example:

User is not logged in, there is a need to log in to comment. Send: 401 Unauthorized

The user is logged in, trying to comment on a closed thread. 403 Forbidden or 400 Bad Request .


Comments