Ajax not calling in Laravel 5.8

Web.php file

Route::group(['middleware'=>['auth','admin']], function(){
Route::get('/admin_addEngagementData', '[email protected]');
Route::post('/admin_insertEngagementData', '[email protected]');


@extends('layouts.admin') @section('title') LeapForWord | Content Management @endsection @section('content')
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header card-header-primary">
<h4 class="card-title">Add DataTypes</h4>
<div class="card-body">
<div class="table-responsive">
<form method="post" id="dynamic_form">

<span id="result"></span>
<table class="table table-bordered table-striped" id="user_table">
<th class="text-center">Data</th>
<th class="text-center">Type Of Data</th>
<th class="text-center">Action</th>

<td colspan="2" align="right">&nbsp;</td>
<input type="submit" name="save" id="save" class="btn btn-primary" value="Save" />
@endsection @section('scripts')
$(document).ready(function() {

var count = 1;


function dynamic_field(number) {
html = '<tr>';
html += '<td><input type="text" name="datatype[]" class="form-control" /></td>';
html += '<td><input type="text" name="subdatatype[]" class="form-control" /></td>';
if (number > 1) {
html += '<td><button type="button" name="remove" id="" class="btn btn-danger remove">Remove</button></td></tr>';
} else {
html += '<td><button type="button" name="add" id="add" class="btn btn-success">Add</button></td></tr>';

$(document).on('click', '#add', function() {

$(document).on('click', '.remove', function() {

$('#dynamic_form').on('submit', function(event) {
url: '',
method: 'post',
data: $(this).serialize(),
dataType: 'json',
beforeSend: function() {
$('#save').attr('disabled', 'disabled');
success: function(data) {
if (data.error) {
var error_html = '';
for (var count = 0; count < data.error.length; count++) {
error_html += '<p>' + data.error[count] + '</p>';
$('#result').html('<div class="alert alert-danger">' + error_html + '</div>');
} else {
$('#result').html('<div class="alert alert-success">' + data.success + '</div>');
$('#save').attr('disabled', false);



class DashboardController extends Controller
public function getEngagementForm(){
return view('admin.admin_addEngagementData');
return view('auth.login');

public function insertEngagementData(Request $request){
// dd($request);
$id = Auth::user()->id;

$rules = array(
'datatype.*' => 'required',
'subdatatype.*' => 'required'

$error = Validator::make($request->all(), $rules);
return response()->json([
'error' => $error->errors()->all()

$datatype = $request->datatype;
$subdatatype = $request->subdatatype;

for($count = 0; $count < count($datatype); $count++){
$data = array(
'user_id' => $id,
'datatype' => $datatype[$count],
'subdatatype' => $subdatatype[$count]
$insert_data[] = $data;

return response()->json([
'success' => 'Data Added successfully.'
return view('auth.login');


I had kept my blade.php file inside view/admin/admin_addEngagement.blade.php file. but I am not getting any output and in console, i am getting error:- jquery.min.js:3049 POST- 500 (Internal Server Error)

how can I resolve this issue?

from Newest questions tagged laravel-5 – Stack Overflow https://ift.tt/2Ys1Wak

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.