I am performing a crud with ajax in laravel. i want to show a modal popup to edit the data from ajax in laravel but i face this error
Missing required parameters for [Route: edit_degree] [URI: setup/edit_degree/{id}]
here is the code of my controller function
public function edit_degree($id)
{
$degree_data = DB::select("select degree_id, degree_name, degree_short_name, active_flag from setup.su_degree where degree_id = '$id'");
if($degree_data == true)
{
return response()->json(['result' => 'success', 'degree_id' => $degree_id]);
}
else
{
return response()->json(['result' => 'error']);
}
}
here is the code of my view:
@extends('app')
@section('content')
<section class="content-header">
<h1>
<a type="button" href="" class="btn btn-outline-secondary btn-sm m- 1" data-toggle="modal" data-target="#myModal" style="padding: 0.15rem; height: 27px; right: 53px; position: absolute; top: 41px;" title="Add New"><i class="text-20 i-Add"></i></a>
</h1>
</section>
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover compact nowrap" cellpadding="0" border="0" id="example" style="width: 100%;">
<thead>
<tr class="bg-primary text-white" >
<th class="text-center" style="font-size:14px; text-align: left; font-weight: bold;">#</th>
<th class="text-center" style="font-size:14px; font-weight: bold;">Degree Name</th>
<th class="text-center" style="font-size:14px; font-weight: bold;">Degree Short Name</th>
<th class="text-center" style="font-size:14px; font-weight: bold;">Action</th>
</tr>
</thead>
<tbody>
@foreach($degree_list as $dl)
<tr>
<td ></td>
<td ></td>
<td ></td>
<td ><a type="button" data-toggle="modal" data-target="#myModal1" onclick="editdegree('')"><i class="text-20 i-Edit"></i></a>
</tr>
@endforeach
</tbody>
</table>
</div>
<!-- Create Modal -->
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Create Degree</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<form method="post" name="add_degree" id="add_degree" >
<input type="hidden" name="id" id="id">
<div class="row">
<div class="col-md-4 form-group mb-3">
<label for="Degree Name">Degree Name</label>
<input type="text" class="form-control" id="degree_name" name="degree_name" placeholder="Degree Name" >
</div>
<div class="col-md-4 form-group mb-3">
<label for="Degree Short Name">Degree Short Name</label>
<input type="text" class="form-control" id="degree_short_name" name="degree_short_name" placeholder="Degree Short Name" >
</div>
<div class="col-md-2 form-group mb-3">
<label></label>
<a class="btn btn-success" id="submit" onclick="adddegree();">Save</a>
<!-- <input type="submit"> -->
</div>
</div>
</form>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- update Modal -->
<div class="modal fade" id="myModal1">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Edit Degree</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<form method="POST" name="edit_degree" id="edit_degree" >
<input type="hidden" name="degreeid" id="degreeid">
<div class="row">
<div class="col-md-4 form-group mb-3">
<label for="Degree Name">Degree Name</label>
<input type="text" class="form-control" id="degree_name1" name="degree_name1" >
</div>
<div class="col-md-4 form-group mb-3">
<label for="Degree Short Name">Degree Short Name</label>
<input type="text" class="form-control" id="degree_short_name1" name="degree_short_name1" >
</div>
<div class="col-md-2 form-group mb-3">
<label></label>
<a class="btn btn-success" id="submit" onclick="updatedegree();">Save</a>
<!-- <input type="submit"> -->
</div>
</div>
</form>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
@endsection
And Here is the code of Jquery Ajax:
<script type="text/javascript">
function editdegree(id){
$.ajax({
url: "",
type: 'get',
dataType: 'json',
data: { id : id },
success: function(data) {
alert(data);
if(data.result == 'success')
{
$('#degree_name1').val(data.degree_name);
$('#degree_short_name1').val(data.degree_short_name);
}
}
});
}
I search alot but could not find any solution of this problem.please help me to resolve this issue. Please help me Thanks.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire