The response is returned as a string, rather than an HTML element. Try
Code:
var returnAsHTML = $(data);
// then..
if (returnAsHTML).find(...) // etc..
// do you need to use find..?
if ($(".error", returnAsHTML).length) {
Do you need to use each()? I suspect you just need to use
first() to retrieve the first (and only) error message.
But if you return just a string rather than '<div>...etc.' then you can just use the string
as is rather than extracting it.
I would consider returning either '
true' or
'Some error message' and check against the text
'true'.