Am tried to select multiple of ids
from the concept of delete multiple ids, but am get the error and ids not passed
this is code i tried
JavaScript
x
105
105
1
<button style="margin-bottom: 10px" class="btn btn-primary delete_all" data-url="{{
2
url('receiveAllUnit') }}">Received All</button>
3
$(document).ready(function () {
4
5
6
$('#master').on('click', function(e) {
7
if($(this).is(':checked',true))
8
{
9
$(".sub_chk").prop('checked', true);
10
} else {
11
$(".sub_chk").prop('checked',false);
12
}
13
});
14
15
16
$('.delete_all').on('click', function(e) {
17
18
19
var allVals = [];
20
$(".sub_chk:checked").each(function() {
21
allVals.push($(this).attr('data-id'));
22
});
23
24
25
if(allVals.length <=0)
26
{
27
alert("Please select row.");
28
} else {
29
30
31
var check = confirm("Are you sure you want to Receive All Units?");
32
if(check == true){
33
34
35
var join_selected_values = allVals.join(",");
36
37
38
$.ajax({
39
url: $(this).data('url'),
40
type: 'POST',
41
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
42
data: 'ids='+join_selected_values,
43
success: function (data) {
44
if (data['success']) {
45
$(".sub_chk:checked").each(function() {
46
$(this).parents("tr").remove();
47
});
48
alert(data['success']);
49
} else if (data['error']) {
50
alert(data['error']);
51
} else {
52
alert('Whoops Something went wrong!!');
53
}
54
},
55
error: function (data) {
56
alert(data.responseText);
57
}
58
});
59
60
61
$.each(allVals, function( index, value ) {
62
$('table tr').filter("[data-row-id='" + value + "']").remove();
63
});
64
}
65
}
66
});
67
68
69
$('[data-toggle=confirmation]').confirmation({
70
rootSelector: '[data-toggle=confirmation]',
71
onConfirm: function (event, element) {
72
element.trigger('confirm');
73
}
74
});
75
76
77
$(document).on('confirm', function (e) {
78
var ele = e.target;
79
e.preventDefault();
80
81
82
$.ajax({
83
url: ele.href,
84
type: 'POST',
85
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
86
success: function (data) {
87
if (data['success']) {
88
$("#" + data['tr']).slideUp("slow");
89
alert(data['success']);
90
} else if (data['error']) {
91
alert(data['error']);
92
} else {
93
alert('Whoops Something went wrong!!');
94
}
95
},
96
error: function (data) {
97
alert(data.responseText);
98
}
99
});
100
101
102
return false;
103
});
104
});
105
kindly can you show me how i can fetch those ids and passed to controller
am expect to update one column like this
JavaScript
1
6
1
RotateDevice::whereIn([ ['DeviceId',$ids]
2
])
3
->update([
4
'status'=>0,
5
]);
6
Advertisement
Answer
In Ajax Call replace From
JavaScript
1
3
1
data: 'ids='+join_selected_values,
2
3
To
JavaScript
1
2
1
data: {ids:join_selected_values},
2
and in Controller
JavaScript
1
7
1
$idsString=$request->input('ids');
2
$idsArray=explode(",",trim($idsString,','));//explode to split ids to array , and trim to ensure if ids received with , at the end or beginning of string.
3
if(!empty($idsArray)){
4
RotateDevice::whereIn('DeviceId',$idsArray)
5
->update(['status'=>0]);
6
}
7