I am working on PHP ajax project. I want to disable and change the button’s text after the success function call in ajax. my ajax function is working fine and I am getting the desired output. just one thing is remaining which is the button thing.
Here is my code for ajax.
$(document).ready(function () {
$(document).on("click", "#add_btn", function (e) {
e.preventDefault();
var id = $(this).val();
var cus_id = $('#customer_selection').val();
if (!cus_id) {
alert("Please select a customer")
} else {
$.ajax({
url: "add_selection_script.php",
type: "POST",
data: {
id: id,
cus_id: cus_id
},
success: function (data) {
// here i want to change button text and disable for click button only
not others because my buttons are dynamic
prop("disabled", true);
html("Added");
}
});
}
});
});
here is the button code
<button type="submit" id="add_btn" value="<? echo $id; ?>">Add to selection</button>