do i have to parse the json myself?
Yes, error responses are not handled by the jQuery Ajax API automatically. You have to do it yourself.
how can i add the error message to the field?
Here is a very quick error handling example: http://jsfiddle.net/hpM6W/
Although a much more comprehensive solution is required. For example, in the example I presented, list twice and see what happens ...
There are many toolkits and libraries for reliable client-side validation and error reporting. I highly recommend looking at the jQuery validation plugin to get started with form validation. You should always perform server side validation and return any errors.
What I did in the past is a hybrid model in which I would do client-side validation as a user-friendliness (better user interface), and also use the jQuery validation plugin to render the server-side validation result using the showErrors method.
Here is a quick example: http://jsfiddle.net/GNq84/ on how to use showErrors to display received error messages from server side validation. Note that in this example, multiple jobs work much better.
However, there is one caveat. showErrors expects these errors: { "element": "message" } , and not what you have: { "element": [ "message1", "message2" ] } , but I will leave this to you to solve: )
source share