When I submit a form, depending on the text in the data, I want JQuery to append the data to the correct DIV. I have a series of validation checks on the blah.php page. If validation fails, a message is returned. If validation is successful, text containing ‘img src’ (i.e. ) is returned.
So if the text returned in ‘data’ contains ‘img src’ I want the data to be appended to the blahupdate div. If ‘data’ does not contain ‘img src’ in its text I want the data to be appended to the blaherror div.
Below is the code that I have so far
<form id="blahform" method="post" enctype="multipart/form-data" action="blah.php">
<input type="file" name="blahfile" />
<button id="blahbutton">Upload</button>
</form>
<div id="blaherror"></div>
<div id="blahupdate"></div>
$('#blahbutton').click(function(){
$('#blaherror').empty();
$('#blahform').ajaxForm(function(data, textStatus){
if ($('data:contains("img src")')){
$('#blahupdate').append(data);
}else{
$('#blaherror').append(data);
}
});
});
I’m assuming that this the
datais a string, but I think the following should work: