this is my ajax script which is uploading the image successfully in MySQL database but the success message is not showing alert or not working, and below is my store method: I have seen other answers but is not working any other answer, like removing datatype: JSON, anyone reviews my code below and sorts out the mistake.
View file:
$('#party_create_form').on('submit', function(e){
e.preventDefault();
$.ajax({
url: '{{route('party.store')}}',
method: 'POST',
data:new FormData(this),
dataType: "JSON",
contentType: false,
cache: false,
processData: false,
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
success:function(data)
{
alert('hi');
}
})
});
Controller File:
public function store(PartyRequest $request)
{
$validator = Validator::make($request->all(), [
'name' => 'required|unique:parties',
'party_logo' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
if ($validator->passes()) {
$input['party_logo'] = time().'.'.$request->party_logo->extension();
$request->party_logo->move(public_path('party_logo'), $input['party_logo']);
$data = ['name' => $request->name,'party_logo'=>$input['party_logo']];
Party::create($data);
return response()->json();
} else {
return response()->json();
}
}