I encountered the following error:
"{"status":"error","msg":"Category was not created"}"
Below is my Controller Function where I execute the action :
function create_category(Request $request){
if($request->ajax()){
$category_name = $request->input('create_category');
DB::table('tbl_smscategories')->insert($category_name);
$response = array(
'status' => 'success',
'msg' => 'Category created successfully',
);
return Response::json($response);
}else{
$response = array(
'status' => 'error',
'msg' => 'Category was not created',
);
return Response::json($response);
}
}
I received this error message
"{"status":"error","msg":"Category did not created"}"
Here is my ajax Code for performing the action :
<script type = "text/javascript">
$('#add-order').click(function(e) {
e.preventDefault();
var inputcreate_category = $('input[name="create_category"]').val();
var token = $('input[name="_token"]').val();
var data = {
create_category: inputcreate_category,
token: token
};
var request = $.ajax({
url: "/create-category",
type: "POST",
data: data,
dataType: "html",
});
request.done(function(msg) {
var response = JSON.parse(msg);
console.log(response.msg);
});
request.fail(function(jqXHR, textStatus) {
console.log("Request failed: " + testStatus);
});
}); < /script>
I got this specific error regarding category creation "{"status":"error","msg":"Category did not created"}"
HTML Element :
<form method="post" action=" {{ route('createcategory') }} " enctype="multipart/form-data" method="post">
{{ csrf_field() }}
<div class="form-group">
<label>Category Name</label>
<input type="text" name="create_category" id="create_category" class="form-control" placeholder="Enter Category Name">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary" id="create">Create</button>
</div>
</form>