I am doing validation server side, If fails I am passing back json data with the errors.
I’m not worried about displaying the errors on page but happy with just a simple alert().
How can I display the errors nicely while using a $each function with jquery.
Here is some json data.
{"error":["The Firstname field is required.","The Lastname field is required.","The Address 1 field is required.","The City field is required.","The Zipcode field is required.","The Receive Mailing List field is required."]}
Displaying messy would be like
$.each(msg.error, function(k, v) {
alert(v);
});
Hope you can advise.
If you want an alert but not individually for each message, you can just use
.join()on the array here, like this:You can give it a try here, you’ll get one alert with a message on each line, like this: