Ajax call on change not working in laravel 5.8

web.php file

Route::group(['middleware'=>['auth','lfwuser']], function(){
Route::get('/lfwuser_addEngagementData', '[email protected]');

Route::post('/lfwuser_SubDataEngagementData', '[email protected]');
});

LfwDashboardController File.

public function getEngagementData(){
if (Auth::check()) {
$data = DB::table('table')
->select('col')
->distinct('col')
->get();
return view('lfwuser.lfwuser_addEngagementData')->with('data', $data);
}
else {
return view('auth.login');
}

}

public function fetchSubData(Request $request){
if (Auth::check()) {
echo "Hello World";
}
else {
return view('auth.login');
}

}

Blade file

@extends('layouts.lfwuser') @section('title') LeapForWord | Content Management @endsection @section('content')
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<center>
<h4 class="card-title">Add Data</h4>
</center>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-3">
</div>
<div class="col-md-6">
<form action="/lfwuser_addEngagementData" method="POST" enctype="multipart/form-data ">



<div class="form-group">
<label for="dataType">Data Type</label>
<select class="form-control" name="dataType" id="dataType" required>
<option value=" ">--- Select ---</option>
@foreach($data as $datatype)
<option value=""></option>
@endforeach
</select>
</div>

<div class="form-group">
<label for="subdataType">Sub Data Type</label>
<select class="form-control" name="subdataType" id="subdataType" required>
<option value="">--- Select ---</option>
</select>
</div>

<div class="form-group">
<input type="hidden" class="form-control" name="subDataId" id="subDataId" required>
</div>

<div class="form-group">
<label for="filellink">Link:</label>
<input type="text" class="form-control" name="filellink" id="filellink" required>
</div>

<div class="form-group">
<div class="row">
<button type="submit" class="btn btn-outline-success text-center">Submit</button>
</div>
</div>
</form>
</div>
<div class="col-md-3"></div>
</div>
</div>
</div>
</div>
</div>
@endsection @section('scripts')
<script>
$(document).ready(function() {
$("#dataType").change(function() {
let datatype = $("#dataType").val();
let _token = $('input[name="_token"]').val();

console.log("Data Type: " + datatype);

if (dataType != '') {
$.ajax({
url: "/lfwuser_SubDataEngagementData",
method: "POST",
dataType: "json",
data: {
datatype: datatype,
_token: _token
},
success: function(response) {
console.log("hi" + response);
}
});
} else {

}

});
});
</script>
@endsection

Nothing gets in response and no error on the console. How should I resolve this issue? The form is shown when the user logged in into the system The blade file store inside the view/user folder. I guess the mistake in the URL part. URL is not calling properly, sometimes it shows error 419 for file, It is taking much time please let me know where I am doing wrong?

from Newest questions tagged laravel-5 – Stack Overflow https://ift.tt/3d8FmHT
via IFTTT

Related Posts

Codeigniter : Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE) in Laravel project

I’m getting following error: **Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE)** Note : It’s working in local but facing issue in production server. private…

Firebase receive notification while tab is active or on focus

What i want is to be able to perform an action when a user receives a notification while the browser is open and tab is active or…

Laravel’s alias loader does not find class

We have a legacy project that we cannot update and we need to make some changes in symfony’s Response.php in vendor. We have solved this by copying…

Laravel 5 – generic document management

I have a system where you can create different types of unique documents. For instance, one document is called Project Identified and this expects certain inputs. Originally,…

Laravel Nova limit the results in indexQuery

I ran intro a situation where I need to limit the results of a resource to only 3 results. To be more specific, based on the logged…

Auditoria en laravel 5.8 [closed]

Cómo puedo automatizar el registro de actividades de un usuario en laravel? Si un usuario ingresa a un app de laravel, debo guardar toda su actividas, a…

Leave a Reply

Your email address will not be published.