I am trying to update the value (views) of a table row using Ajax when an onclick event is called.
The views are updated but the problem is that I can't get the new value of the views to show on that particular table row.
I have to refresh the page to see the updated views value and that's not what I want.
I want it updated dynamically as the button is clicked. This is what I am doing.
<table>
@foreach($data as $datum)
<tr>
<td><span class="view2"></span></td>
<td><button class="btn btn-default" onclick="bigImg(event)" value="">click</button></td>
</tr>
@endforeach
</table>
<script>
function bigImg(event) {
var game_id = event.target.value;
var obj = $(this);
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
type:'POST',
dataType:'JSON',
url:'',
data:'game_id='+game_id,
success:function(data)
{
var data=eval(data);
message=data.message;
//console.log(message);
obj.closest('tr').find(".view2").text(message);
}
});
}
</script>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire