I answered a question yesterday that had been put on-hold for no MCVE.
The OP (a new member) needed a little instruction and with some editing help the question had sufficient information to provide a definitive answer as to why his code wasn't working.
Note: this is the only version I could pull from Google Cache
I'm trying to change the text inside of a button in the click event after an ajax request has completed successfully.
For some reason I am unable to update the text.
Jquery:
$(".addfriend").click(function(){ $.ajax({ type: "POST", url: "/pages/send_friend_request.php", data: {userid: $(this).data('userid')}, success: function(data) { if(data == 'success') $(this).html(' Request Sent'); else alert('Error: Could not send request. > Report this to admin.'); } }); });
HTML Button:
<button class="addfriend" data-userid="<?=$member['id']?>" type="button" name="button">+Add as Friend</button>
The reason why the text isn't being updated is because the use of $(this)
within the ajax callback without providing context or a reference.
No, the question is not a gem and could've used some more editing, but, it is an answerable question that was on-topic, so, why was it deleted?