This is our ruby on rails view from where called our jquery function().
<td id= <%= "reject_#{event.id}" %>>
<%= button_tag "Accept" , :onclick => "abc('#{event.id}', 'Accept');" %>
<%= button_tag "Reject" , :onclick => "abc('#{event.id}', 'Reject');" %>
</td>
This is our jquery function() from where we called ajax().
abc = function(id1 , user_status){
console.log(user_status);
console.log(id1);
var url;
if(user_status == 'accept'){
url = "/events/" + id1 + "/accept_event/";
}
else {
url = "/events/" + id1 + "/reject_event/";
}
console.log(url);
$.ajax({
url: url,
beforeSend: function(xhr){xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))},
type: "POST",
dataType: "JSON",
data: {'event_id': id1 },
success: function(data){
$("#success1").html("ACCEPTED");
var a = 'reject_' + id1;
$("#"+a).html(user_status);
},
error: function(error){
alert(error.responseText)
}
});
0 Comment(s)