Reputation: 441
I have a form that get's processed via jQuery Ajax. Everything works well on the backend. When the HTML comes back the script successfully performs the following: $("#msgMailingList").html(data);
However, I would like to hide the form if everything was processed correctly on the backend. I'm currently saying if what came back in HTML has a class formAction, then it should be ok. If what comes back has class called formErrors, do not hide the form.
Error via Firebug: "data.hasClass is not a function."
$(function(){
$("#formMailingList").submit(function(e){
e.preventDefault();
dataString = $("#formMailingList").serialize();
$.ajax({
type: "POST",
url: "ajaxMailingList.php",
data: dataString,
dataType: "html",
success: function(data) {
$("#msgMailingList").html(data);
// the following doesn't work
if (data.hasClass("formActions"))
{
$("#formMailingList").hide();
}
}
});
});
});
Thanks for any help you can provide.
Upvotes: 1
Views: 1545
Reputation: 76870
you should wrap that in a jQuery object (this assumes that you are returning a simple html element like <div class='formActions'>Everithing ok</div>
)
// the following doesn't work
if ($(data).hasClass("formActions") )
{
$("#formMailingList").hide();
}
Upvotes: 2