Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
i am uploading Image through AJAX in laravel, which is successfully uploaded but Successfull fucntion is not working

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();
  }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try this

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);
      $msg = "success";
      $array =  array("status" => 200, "msg" => $msg, "result" => array());

    } else {

      $msg = "Failed";
      $array =  array("status" => 400, "msg" => $msg, "result" => array());

    }
    return \Response::json($array);
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!