We received a question regarding the JSON responses of programming assignment 1.
You might think that all HTTP responses must contain HTML of the next page to display. However, it is possible to make the server respond with JSON-formatted data. In fact, we tried this out in the practice session for Rails. As stated in the assignment page, responses from the back-end API must be decodable in JSON format.
You can use AJAX to make your front-end receive this JSON response and create a message box with the alert() function. It doesn't matter how you display the error, because we will grade the front-end manually.
You may also use the Rails method respond_to to respond differently depending on which format the requester wants to receive the response.
We received a question regarding the JSON responses of programming assignment 1.
You might think that all HTTP responses must contain HTML of the next page to display. However, it is possible to make the server respond with JSON-formatted data. In fact, we tried this out in the practice session for Rails. As stated in the assignment page, responses from the back-end API must be decodable in JSON format.
You can use AJAX to make your front-end receive this JSON response and create a message box with the
alert()
function. It doesn't matter how you display the error, because we will grade the front-end manually. You may also use the Rails methodrespond_to
to respond differently depending on which format the requester wants to receive the response.