Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Text on button with Jquery after post

Tags:

jquery

ajax

I am posting some data using ajax and want to change the button text. I don't really know where to start. The code I have so far is below:

$("input[type='button'][name='Subscribe']").click(function(e){
$.ajax({
   type: "POST",
   url: "test.php",
   data:{
    id: $(this).attr('id'),
    idMembers: $(this).attr('idMembers')
    },
   success: function(msg){
       alert("Subscribed");

   }
})
});
like image 835
Textus Avatar asked Apr 27 '26 10:04

Textus


1 Answers

$("input[type='button'][name='Subscribe']").click(function(e){
$this = $(this);
$this.val("processing") // or: this.value = "processing";  
$this.prop('disabled', true); // no double submit ;)
$.ajax({
   type: "POST",
   url: "test.php",
   data:{
    id: $this.attr('id'),
    idMembers: $this.attr('idMembers')
    },
   success: function(msg){
       alert("Subscribed");
       $this.val("i'm finally done!"); // pfewww, that's was hard work!
   }
})
});
like image 120
roselan Avatar answered Apr 29 '26 10:04

roselan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!