我想隐藏上载按钮,并在运行Ajax之后将用户名和上载时间附加到所选行中。
我可以从id = csv_id中获取值,但是我无法隐藏id = upload按钮并将结果附加到id =#username和id =#upload_time
<table class="table table-hover" id="csvtable">
<tbody>
@foreach($csvs as $indexKey => $csv)
<tr>
<td id="username">{{$csv->username ?? ''}}
@if($csv->username == null & $csv->cp!=0)
<input type="text" id="csv_id" value="{{$csv->id}}" hidden>
<button id="upload" type="button" class="btn btn-outline-primary">Upload</button>
@endif
</td>
<td id="upload_time">
@isset($csv->upload_time)
{{date('Y/m/d h:i a', strtotime($csv->upload_time))}}
@endisset
</td>
</tr>
@endforeach
</tbody>
</table>
<script>
$("table tr").on("click", function(event){
event.preventDefault();
$.ajax({
type: "POST",
url: "/url/",
data: {
csv_id: $(this).find("#csv_id").val()
},
success: function(result) {
$(this).find("#upload").hide();
$(this).find("#username").append(result.username);
$(this).find("#upload_time").append(result.upload_time);
}
})
});
</script>