Reputation: 773
I have an AJAX call to submit a form and on success I want to display the PHP success message or Error message.
Here is my AJAX success:
success: function (data) {
resultSuccess = $(data).find("#success");
resultError = $(data).find("#error");
$('#resultBlock').html(resultSuccess);
$('#resultBlock').html(resultError);
}
If I remove one of them it works. For example if I write it like this:
success: function (data) {
resultSuccess = $(data).find("#success");
$('#resultBlock').html(resultSuccess);
}
I works with no problem its only when I add the other one is when it stops working. How do I write it in a way to show one and/or both messages?
Upvotes: 2
Views: 131
Reputation: 17616
$('#resultBlock').html(resultError);
This will replace your success message. Why don't you just append it? Assuming your resultSuccess/resultError is html code (in fact plain text could be appended as well.. confirmation needed).
$('#resultBlock').append(resultSuccess);
$('#resultBlock').append(resultError);
You could even do: $('#resultBlock').append(resultSuccess, resultError);
Upvotes: 4