1 year ago

My ajax keep returning 419 and 500 error status

Posted 1 year ago by galih56

I'm making form that's called by ajax and trying to make the form can submit using ajax.This form is supposed to submit the data through route(' everytime i submit the form.It always return 419 status when i don't use csrf_token() in ajax and if i use the csrf_token() in ajax.It always return 500 internal error.Can someone help me to solve this problem.I've been reading almost every discussion that i found in internet but still no answer. Maybe i missed something important on my code.please review my code.


             var formdata=$('#form-ruangrapat').serialize();//should i do this??
//if i should take the value of inputs 1 by 1,please show me the proper way

             var token="{!!csrf_token()!!}"
                data: {formData:formdata,_token:token},

public function store(Request $request)
        $data = new Ruangrapat();
        $data->contact = $request->get('contact');
        return view('ajax-result.ruangrapat.index')->with('status', 'Ruang rapat baru berhasil ditambahkan!');
//is this return value correct??


Route::resource('ruangrapat', 'RuangrapatController');

Please sign in or create an account to participate in this conversation.