DELETE with AJAX (Jquery) not working with Laravel 5.2 - php

I'm trying to delete a row in db with Jquery / Ajax.
I have followed this thread but I can't make it working.
Here is my view:
#foreach($tournaments as $tournament)
<tr id="line" data-id="{{$tournament->id}}">
<td>
{{ $tournament->id }}
</td>
<td>{{ $tournament->owner->name}}</td>
<td class="text-center">
{!! Form::open(['method' => 'DELETE', 'id' => 'formDeleteTourament', 'action' => ['TournamentController#destroy', $tournament->id]]) !!}
{!! Form::button( '<i class="glyphicon glyphicon-remove"></i>', ['class' => 'btn text-warning-600 btn-flat btnDeleteTournament', 'data-id' => $tournament->id ] ) !!}
{!! Form::close() !!}
</td>
</tr>
#endforeach
<script>
$(function () {
$('#.tnDeleteTournament').on('click', function (e) {
var inputData = $('#formDeleteTourament').serialize();
var dataId = $('.btnDeleteTournament').attr('data-id');
console.log(inputData); // displays: _method=DELETE&_token=tGFhaAr5fVhDXEYL3SaXem3WaTNJlSdFEkaVDe9F
console.log(dataId); // displays 1
var $tr = $(this).closest('tr');
swal({
title: "Are you sure?",
text: "You will not be able to recover this Tournament!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#EF5350",
confirmButtonText: "Yes, delete it!",
cancelButtonText: "No, cancel pls!",
closeOnConfirm: false,
closeOnCancel: false
},
function (isConfirm) {
if (isConfirm) {
e.preventDefault();
$.ajax(
{
type: 'POST', // I tried with DELETE too
url: '{{ url('/tournaments/') }}' + dataId,
data: inputData,
success: function (msg) {
console.log('success'); // It triggers!
$tr.find('td').fadeOut(1000, function () {
$tr.remove();
});
swal({
title: "Deleted!",
text: "Tournament has been deleted.",
confirmButtonColor: "#66BB6A",
type: "success"
});
},
error: function () {
swal("Oops", "We couldn't connect to the server!", "error");
}
}
)
}
else {
swal({
title: "Cancelled",
text: "Your Tournament is safe :)",
confirmButtonColor: "#2196F3",
type: "error"
});
}
});
});
});
Here is my contoller:
public function destroy(Tournament $tournament)
{
$tournament->delete();
return response(['msg' => 'Product deleted', 'status' => 'success']);
}
Before, I had it working without AJAX so route is OK.
Everything works fine (modals shows) but it doesn't delete my tournament
I am new to JS / JQuery, so I don't know what's going on.
Any idea how to fix it?

You need to pretty much change all your references to use class as a selector. I am only guessing on the Laravel stuff, also make your id's unique (I appended tournament Id), but it all needs to change to class:
Guessing on this, not familiar with the syntax
#foreach($tournaments as $tournament)
<tr id="line{{$tournament->id}}" data-id="{{$tournament->id}}" class="parentTr">
<td>
{{ $tournament->id }}
</td>
<td>{{ $tournament->owner->name}}</td>
<td class="text-center">
{!! Form::open(['method' => 'DELETE', 'class' => 'formDeleteTourament', 'action' => ['TournamentController#destroy', $tournament->id]]) !!}
{!! Form::button( '<i class="glyphicon glyphicon-remove"></i>', ['class' => 'btn text-warning-600 btn-flat btnDeleteTournament', 'data-id' => $tournament->id ] ) !!}
{!! Form::close() !!}
</td>
</tr>
#endforeach
Javascript Changes
<script>
$(function () {
$('.btnDeleteTournament').on('click', function (e) {
var inputData = $(this).parents('.formDeleteTourament').serialize();
var dataId = $(this).data('id');
var $tr = $(this).closest('tr');
swal({
title: "Are you sure?",
text: "You will not be able to recover this Tournament!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#EF5350",
confirmButtonText: "Yes, delete it!",
cancelButtonText: "No, cancel pls!",
closeOnConfirm: false,
closeOnCancel: false
},
function (isConfirm) {
if (isConfirm) {
e.preventDefault();
$.ajax({
// I don't you know if you have to escape the inner
// quotes or not, that is a framework syntax thing
url: '{{ url('/tournaments/') }}',
type: 'POST',
// Just include the id in a post data object
data: { form: inputData, id: dataId },
success: function (msg)
{
console.log(msg);
$tr.find('td').fadeOut(1000, function() {
$tr.remove();
});
swal({
title: "Deleted!",
text: "Tournament has been deleted.",
confirmButtonColor: "#66BB6A",
type: "success"
});
},
error: function()
{
swal("Oops", "We couldn't connect to the server!", "error");
}
});
}
else {
swal({
title: "Cancelled",
text: "Your Tournament is safe :)",
confirmButtonColor: "#2196F3",
type: "error"
});
}
});
});
});
</script>

Related

Creating Dynamic Table using PHP and Ajax to insert data into table, unable to use buttons if not within view or first page

Lets Get straight to the point:
I have created a data table using dynamic data from the DB. i call the data using php and insert it into the table.
<?php
$getAttendance = $functions->runSQL("dynamic data sql query ");
$getAttendance->execute();
$attendance = $getAttendance->fetchAll(PDO::FETCH_ASSOC);
foreach ($attendance as $key => $data) {
$getEmployeeName = $functions->runSQL("another sql query to call firstname and last name");
$getEmployeeName->execute() ;
$employeeName = $getEmployeeName->fetchAll(PDO::FETCH_ASSOC);
foreach ($employeeName as $key => $name) {
?>
<tr>
<td><?= $data['date']; ?></td>
<td><?= $data['employee_id']; ?></td>
<td><?= $name['firstname'] . " " . $name['lastname']; ?></td>
<td><?= $data['clock_in']; ?></td>
<td><?= $data['clock_out']; ?></td>
<td>
<button class="btn btn-warning editAttendance" id="editAttendance-<?= $data['id']; ?>" data-id="<?= $data['id']; ?>"><i class="fa fa-edit"></i> EDIT</button>
<button class="btn btn-danger deleteAttendance" id="deleteAttendance-<?= $data['id']; ?>" data-id="<?= $data['id']; ?>"><i class="fa fa-trash"></i> DELETE</button>
</td>
</tr>
<?php
}
}
?>
The table works exactly how i expected it to output and display. Although the edit and delete buttons work ONLY on the first page, after the user displays the second page and any page after that, the "Tools" button become non-existent.
GIF Displaying Page 2 edit/delete not working
As you can see in the above GIF, the edit and delete functions work perfectly until the second page of the pagination is loaded.
This goes for all my tables. if the table is not fully visible the buttons (edit/delete) do not work as well. Im not to sure if its the way the buttons interact with the table or sweetalert.
Not Visible
Not Visible
Visible but unable to work or interact with sweetalert and ajax edit or delete calls (both work as demonstrated in the first GIF)
Visible
<script>
$(document).ready(function(e) {
$('[id^=editAttendance]').on('click', function(e) {
e.preventDefault();
var id = $(this).data('id');
swal.showLoading();
$.ajax({
type: "POST",
url: "<?= $site->baseURL; ?>/",
dataType: "json",
data: { id: id},
success: function(response) {
Swal.fire({
title: "<div style='color:orange;'>Update Attendance</div>",
html: "<div><label>Date</label> <input class='form-control' type='date' value='" + response[0]['date'] + "' id='attendanceDate' placeholder=" + response[0]['date'] + " /></div><br />" +
"<div><label>Clock In</label> <input class='form-control' id='attendanceClockIn' type='time' value='" + response[0]['clock_in'] + "' placeholder='" + response[0]['clock_in'] + "' /></div><br />" +
"<div><label>Clock Out</label> <input class='form-control' id='attendanceClockOut' type='time' value='" + response[0]['clock_out'] + "' placeholder='" + response[0]['clock_out'] + "' /></div><br />",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'YES, EDIT IT!',
cancelButtonText: 'CANCEL'
}).then((result) => {
if (result.isConfirmed) {
var attendanceDate = $('#attendanceDate').val();
var attendanceClockIn = $('#attendanceClockIn').val();
var attendanceClockOut = $('#attendanceClockOut').val();
if ( attendanceDate == "" || attendanceClockIn == "" || attendanceClockOut == "") {
Swal.fire({
icon: 'error',
text: 'please enter a value in either inputs'
});
} else {
Swal.fire({
title: "<div style='color:red;'>Are You Sure ?</div>",
icon: 'question',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'YES!',
cancelButtonText: 'CLOSE'
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
type: "POST",
url: "<?= $site->baseURL; ?>/",
dataType: "json",
data: {
id:id,
dates: attendanceDate,
clockIn: attendanceClockIn,
clockOut: attendanceClockOut
},
success: function(data) {
Swal.fire({
icon: data.success,
title: 'Attendance Edited!',
confirmButtonColor: '#28a745',
confirmButtonText: 'CLOSE!',
text: 'Click CLOSE to continue.',
}).then((result) => {
if (result.isConfirmed) {
location.reload();
}
});
},
error: function(data) {
console.log(data);
}
});
}
});
}
}
});
},
error: function (response) {
swal.fire(
"Internal Error",
"Oops, Something Happened, contact webmaster", // had a missing comma
"error"
);
}
});
});
$('[id^=deleteAttendance]').on('click', function(e) {
e.preventDefault();
var id = $(this).data('id');
$.ajax({
type: "POST",
url: "<?= $site->baseURL; ?>/",
dataType: "json",
data: { id:id },
success: function(data) {
Swal.fire({
title: "<div style='color:red;'>Delete Attendance</div>",
icon: 'question',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'YES!',
cancelButtonText: 'CLOSE',
html: "<strong>You are about to remove <h4 style='color:red;'>" + data[0]['employee_id'] + " :: " + data[0]['date'] + " : " + data[0]['clock_in'] + "</h4></strong>"
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
type: "POST",
url: "<?= $site->baseURL; ?>/",
dataType: "json",
data: {id: id},
success: function(data){
Swal.fire({
icon: data.success,
title: 'Attendance Deleted!',
confirmButtonColor: '#28a745',
confirmButtonText: 'CLOSE!',
text: 'Click CLOSE to continue.'
}).then((result) => {
if (result.isConfirmed) {
location.reload();
}
});
},
error: function(data){
swal.fire(
"Internal Error",
"Oops, Something Happened, contact webmaster.", // had a missing comma
"error"
);
}
});
}
});
},
error: function(data){
console.log(data);
}
});
});
$('#add-new-attendance').on('click', function(e) {
e.preventDefault();
Swal.fire({
title: "<div style='color:green;'>Add Attendance</div>",
html: "<div><label>Employee ID</label> <input class='form-control' type='text' id='attendanceEmployeeID' placeholder='EG: FSJXXXX' required autofocus /></div><br />" +
"<div><label>Date</label> <input class='form-control' id='attendanceDate' type='date' placeholder='100' required /></div><br />" +
"<div><label>Clock In</label> <input class='form-control' id='attendanceClockIn' type='time' placeholder='100' required /></div><br />" +
"<div><label>Clock Out</label> <input class='form-control' id='attendanceClockOut' type='time' placeholder='100' required /></div><br />",
icon: 'info',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'YES, ADD IT!',
cancelButtonText: 'CANCEL'
}).then((result) => {
if (result.isConfirmed) {
var description = $('#deductionDescription').val();
var amount = $('#deductionAmount').val();
if (description == "" || amount == "") {
Swal.fire({
icon: 'error',
text: 'please enter a value in either inputs'
});
} else {
$.ajax({
type: "POST",
url: "<?= $site->baseURL; ?>/",
dataType: "json",
data: {
description: description,
amount: amount
},
success: function(data) {
Swal.fire({
icon: data.success,
title: 'Deduction Added!',
confirmButtonColor: '#28a745',
confirmButtonText: 'CLOSE!',
text: 'Click CLOSE to continue.',
}).then((result) => {
if (result.isConfirmed) {
location.reload();
}
});
},
error: function(data) {
console.log(data);
}
});
}
}
});
});
});
</script>
Anyone else have this issue using datatables js ?
Is this a glitch in datatables or an error on my side for not including anything to handle the next page or when the buttons are not visible?
What i have tried:
- Redesign the entire table (did not work)
- Changed All the jquery and ajax call (simplified but still did not work)
What did work:
- Displaying the full table without the pagination seems to solve this issue. Although it would not be wise to load 100's of pages and display them in one page (cannot use as a fix).
Thank You for taking the time to read and help me asses the situation as this is the first time this has occurred. Never happened before with datatables.
You should replace every jQuery click event listener with a click listener on the body filtered by a selector.
Instead of:
$('[id^=editAttendance]').on('click', function(e) {...});
Try:
$('body').on('click', '[id^=editAttendance]', function(e) {...});
In this way it will work also for buttons that are attached to the DOM after the initial rendering of the page.
See here for the docs: https://api.jquery.com/on/

Confirm delete using swal on laravel 5.8

I got some troubles when using swal to confirm delete, I do not know how to make it work
here is my blade view file:
<form action="{{ route('user.destroy', $us->id)}}" method="post">
#method('DELETE')
#csrf
<input class="btn btn-danger" type="submit" value="Delete" />
</form>
and the script using swal
<script>
//== Class definition
var SweetAlert2Demo = function() {
//== Demos
var initDemos = function() {
$('.btn-danger').click(function(e) {
e.preventDefault();
swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
buttons:{
confirm: {
text : 'Yes, delete it!',
className : 'btn btn-success'
},
cancel: {
visible: true,
className: 'btn btn-danger'
}
}
}).then((Delete) => {
if (!Delete) {
e.preventDefault();
}
});
});
};
return {
//== Init
init: function() {
initDemos();
},
};
}();
//== Class Initialization
jQuery(document).ready(function() {
SweetAlert2Demo.init();
});
</script>
the version of swal is https://sweetalert.js.org not https://sweetalert2.github.io/
And I'm using route resource on laravel 5.8
thanks you!
Update in case of Loops
You should give an id to your form and then in the swal callback submit the form by using the ID
<form action="{{ route('user.destroy', $us->id)}}" method="post" id="yourFormId">
Your JS Click button is almost same. Just some small change in the Swal JS Callback Method
$('.btn-danger').click(function(e) {
var $form = $(this).closest("form"); //Get the form here.
e.preventDefault();
swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
buttons:{
confirm: {
text : 'Yes, delete it!',
className : 'btn btn-success'
},
cancel: {
visible: true,
className: 'btn btn-danger'
}
}
}).then((Delete) => {
console.log(Delete); //This will be true when delete is clicked
if (Delete) {
$form.submit(); //Submit your Form Here.
//$('#yourFormId').submit(); //Use same Form Id to submit the Form.
}
});
});
Use GET method instead of POST.
And no need to use button or combine anything.
Try this example,which always works with my all projects.
As
Use anchor tag, Not button
<a class="btn btn-action text-danger" title="Delete" data-toggle="tooltip" onclick="deletefunction({{$your_id}})"><i class="fa fa-trash"></i></a>
Add Script As,
<script>
var deletefunction = function(id){
swal({
title: "Are you sure you want to Delete this?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
closeOnConfirm: false,
preConfirm: function(result) {
window.location.href = '{{url('/your_route/delete')}}/'+id;
},
allowOutsideClick: false
});
};
</script>

Laravel Route call via AJAX gets wrong URL 404 (Not Found)

I have the following route defined in my web.php
Route::delete('/contributions/contribution/destroy', 'ContributionController#destroy');
In my blade file I have a button that when clicked displays a sweetalert to confirm deletion. This works correctly, but when the user presses the delete button instead of it going to the URL defined in Ajax it goes to an incorrect URL and logs the following error:
jquery.min.js:4 DELETE http://localhost/contributions/batches/batch/edit 404 (Not Found)
Here is button code
<td class="text-center"><button type="button" class="btn btn-danger btn-sm btn-icon btn-destroy"
data-batch-id="{{ $batch->id }}"
data-id="{{ $contribution->id }}"
data-amount="${{ number_format ($contribution->contribution_amount, 2, '.', ',') }}"
data-contributor="{{ $contribution->first_name.' '.$contribution->last_name }}"
><i class="fa fa-times"></i></button>
</td>
Here is my script
<script>
$(document).on('click', '.btn-destroy', function (e) {
e.preventDefault();
var batchId = $(this).data('batch-id');
var id = $(this).data('id');
var amount = $(this).data('amount');
var contributor = $(this).data('contributor');
swal({
title: "Delete?",
text: "Do you want to delete contribution for "+ amount +" from "+ contributor +"?",
type: "error",
showCancelButton: true,
confirmButtonClass: 'btn-danger',
confirmButtonText: "Delete",
closeOnConfirm: false
},
function() {
$.ajax({
url: "{{ url('/contributions/contribution/destroy') }}",
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
type: "DELETE",
data: {batch:batchId, contribution:id},
success: function (data) {
console.log(data);
}
});
});
});
oddly enough, refreshing the page after the error returns my session flash message from my controller's destroy function
*Note: I did add the DELETE verb to IIS, before this I was receiving:
405 (METHOD NOT ALLOWED)
Any ideas?
After two days of reading and wrenching I have a working solution:
route:
Route::delete('/contributions/contribution/destroy', 'ContributionController#destroy');
link html:
<a href="#" class="btn btn-danger btn-sm btn-icon btn-destroy"
data-id="{{ $contribution->id }}"
data-amount="${{ number_format ($contribution->contribution_amount, 2, '.', ',') }}"
data-contributor="{{ $contribution->first_name.' '.$contribution->last_name }}"><i class="fa fa-times"></i></a>
jquery/ajax:
<script>
$(document).on('click', '.btn-destroy', function (e) {
e.preventDefault();
var contributionId = $(this).data('id');
var amount = $(this).data('amount');
var contributor = $(this).data('contributor');
swal({
title: "Delete?",
text: "Do you want to delete contribution for "+ amount +" from "+ contributor +"?",
type: "error",
showCancelButton: true,
confirmButtonClass: 'btn-danger',
confirmButtonText: "Delete",
closeOnConfirm: false
},
function() {
$.ajax({
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
method: "DELETE",
url: "{{ url('/contributions/contribution/destroy') }}",
data: {contributionId:contributionId},
success: function (msg) {
if ( msg.status === 'success' ) {
swal("Deleted", msg.msg, "success");
setInterval(function() {
window.location.reload();
}, 3900);
}
},
error: function(msg) {
swal("Error!", "Something went wrong.", "error");
console.log(msg.status);
}
});
});
});
</script>
controller:
public function destroy(Request $request)
{
if ( $request->ajax() ) {
Contribution::find($request->contributionId)->delete();
return response(['msg' => 'Entry deleted', 'status' => 'success']);
}
return response(['msg' => 'Failed deleting the entry', 'status' => 'failed']);
}
Works perfectly!
Try this style of ajax
$.ajax({
url: "{{ url('/contributions/contribution/destroy') }}",
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
'data':{
'_method':'delete',
'_token':'{{ csrf_token() }}',
},
'method':'post'
});
in my case I removed the error by running simple classic:
php artisan route:clear
or you can launch that remotely. Create a route and a Controller and call it via browser link:
Route::get('/b/{x}', 'for_stuff\BController#kukuku');
and put into the controller's function:
Artisan::call('route:clear');
say:
https://mysite/b/r

Can't read responseJSON value in ajax request

This is the view :
{{ Form::open([
'url' => '/contacts/create',
'files' => true
])}}
<div class="row">
<div class="collapse" id="collapseExample">
<div class="col-md-9">
{{ Form::label('group', 'group name')}}
{{ Form::text('group', null, [
'placeholder' => 'Enter group name here',
'class' => 'form-control'
])}}
</div>
<div class="col-md-3">
<button id="add-new-btn" class="btn btn-success"><i class="pe-7s-add-user"></i> Add</button>
</div>
</div>
</div>
{{ Form::close() }}
in my that view i have this script
$("#add-new-btn").click(function(e) {
e.preventDefault();
e.stopImmediatePropagation();
var newGroup = $('#group');
$.ajax({
url: "/groups/autocomplete",
method: "post",
data: {
name: $("#group").val(),
_token: $("input[name=_token]").val()
},
success: function(response) {
console.log(response);
},
error: function(xhr) {
var errors = xhr.responseJSON;
var error = errors.name[0];
if(error) {
newGroup.addClass('has-error');
var inputGroup = newGroup.closest('.col-md-9');
inputGroup.next('text-danger').remove();
inputGroup
.find('input')
.after('<p class="text-danger">' + error + '</p>');
}
}
});
});
and in store method of GroupsController i have a simple Validator that may returns these 2 values:
1.The name field is required
2.The name has already been taken
public function store(Request $request)
{
$this->validate($request, [
'name' => 'required|unique:groups'
]);
}
Now the problem is this :
Every time i try to submit the form, the browser returns this error "errors.name is undefined" in console.
where is the problem?
i had a mistake for accessing property of object, jsonData.errors
var data = xhr.responseText;
var jsonData = JSON.parse(data);
var msg = jsonData.errors.name[0];
console.log(msg);
or
var jsonData = xhr.responseJSON;
var msg = jsonData.errors.name[0];
console.log(msg);

Laravel executing GET instead of POST request

I have form to POST data to Controller and update database
The form in my orders.blade.php
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<select name="selectdb" required>
<option value="" disabled selected>Select Delivery Boy</option>
#foreach($delvery_boys as $delvery_boy)
<option name="selectdb" data-oid="{{$order->id}}" value="{{$delvery_boy->id}}">{{$delvery_boy->name}}</option>
#endforeach
</select>
<button type="submit" class="assigndb-btn btn-floating waves-effect waves-light">
<i class="material-icons">send</i>
</button>
</form>
I am doing an ajax POST request of form data to controller in my orders.blade.php
$(document).one("click", ".assigndb-btn", function () {
$('form').submit(function(event) {
event.preventDefault();
var order_id = $(this).find(":selected").data('oid');
var delivery_boy_id = $(this).find(":selected").val();
var delivery_boy_name = $(this).find(":selected").text();
$.ajax({
url: '{{ url('/manager/assign_orders') }}',
type: 'POST',
data: {"order_id":order_id,"delivery_boy_id":delivery_boy_id},
success: function(data) {
console.log(data);
},
error: function(error) {
console.log(error);
}
});
});
});
And in my OrdersController.php i have the logic to updated the posted data
public function assignDeliveryBoy(Request $request)
{
$assign_delivery_boy = Order::where('id', $request->order_id)->update(['delivery_boy_id' => $request->delivery_boy_id]);
$data = [
'success' => true,
'message' => 'Order has been asigned'
];
return response()->json($data);
}
My Route is
Route::group(['prefix' => 'manager', 'middleware' => ['auth','roles'], 'roles' => 'manager'], function() {
Route::post('/assign_orders', 'OrdersController#assignDeliveryBoy')->name('assignOrder');
});
When i submit the form it suppose to hit the assign_order route and update the database
But in my console i am getting the html code of the page from where i submit the form basically it is executing GET instead of POST
As i checked in browser network whent the response is
Request URL:http://localhost:8000/manager/orders //but i am posting to http://localhost:8000/manager/assign_orders
Request Method:GET
Status Code:200 OK
Remote Address:127.0.0.1:8000
Referrer Policy:no-referrer-when-downgrade
i really don't understand what is wrong
thank you
Try this code.
$.ajax({
url: "{{ url('/manager/assign_orders') }}",
type: 'POST',
data:{
"order_id":order_id,
"delivery_boy_id":delivery_boy_id,
'_token':'{{ csrf_token() }}'
},
success: function(data) {
console.log(data);
},
error: function(error) {
console.log(error);
}
});
Let me know if it works.
Try this:
$.ajax({
url: '{{ route('assignOrder') }}',
type: 'POST',
data: {"order_id":order_id,"delivery_boy_id":delivery_boy_id},
success: function(data) {
console.log(data);
},
error: function(error) {
console.log(error);
}
});
$.ajax({
url: '{{ route("assignOrder") }}',
type: 'POST',
data: {"order_id":order_id,"delivery_boy_id":delivery_boy_id,'_token':'{{ csrf_token() }}'},
success: function(data) {
console.log(data);
},
error: function(error) {
console.log(error);
}
});

Categories