I have a form that saves data to a database with jQuery. On a success response I want to disable the submit button on the form so it can't be resubmitted. I've tried $(this).find("button[type='submit']").prop('disabled',true);
but it's not working and I don't understand why. Can anyone tell me what's wrong?
Form
<form action="" id="like_unlike" method="" enctype="multipart/form-data">
<input type="hidden" name="file" value="<?php echo $page_id;?>" />
<input type="hidden" name="userid" value="<?php echo $_SESSION['user_session'];?>" />
<span> <button type="submit" id="like" class="btn btn-default btn-small" name="like"><span class="icon-heart-empty"id="heart"></span>
<span class="submit-text" id="count"><?php echo $rowcount?></span></button></span>
</form>
jQuery
$("#like_unlike").submit( function(e) { //Second Form
e.preventDefault();
var url = "update.php"; //Grab URL from form
var formdata = $(this).serialize();
console.log(formdata);
$.post(url, formdata, //Post the form
function(response) {
$('#count').html(response);
$(this).find("button[type='submit']").prop('disabled',true);
});
});
});