Reputation: 307
I want to change button text permanently on a successful page submit on ajax call in laravel. Changing text is not a problem, the problem is I want to change the text on a realtime datatable where my data is refreshing after every 10 seconds and when if I change the text on success in Ajax it works but when the datatable is refreshed after 10 sec the button change to it's original text.
This is my Ajax call:
$("#formData").on('submit', function(e) {
e.preventDefault();
$.ajax({
url: "{{ URL::route('update-status-ajax') }}",
method: 'post',
data: $('#formData').serialize(),
success: function(response) {
$(".modal").modal('hide');
$('#formData')[0].reset();
$('#assignBtn').html('Assigned'); //button changes text
toastr.success("Complaint Updated successfully!");
},
error: function(err) {
console.log(err);
toastr.danger(err);
}
});
});
I want to change the text permanently even after the table is refreshed after 10 seconds. What do I do!
Thanks in advance.
Upvotes: 0
Views: 144
Reputation: 22
You should send a data to your backend the text u want to change. f.e. Hello to Hi . so you send new value Hi to your controller(i talk about mvc) and after doing it successfull ajax callback function works and u see Hi instead of Hello even without having refresh and in back you have to say sql or which database you use . just update the data where ... f.e. update Student set StudentStatus = 'text you want to send' where Student Id = {} u must use id in front and send them to back too . maybe u have only 1 row. but try making it for any amount of rows. So u send data of text and data of Id . both are known by you. take them from inside of tag u put in. and receive them in back and insert them. you can just use a void method for that. and ajax success function without and parameter.
Upvotes: 1